CSS - Pseudo-class :enabled



The CSS pseudo-class selector :enabled represents an element that is enabled. An element is in a enabled state, if it can be activated (selected, clicked on, typed into, etc). or accepts focus.

Syntax

:enabled{
	/* ... */
}

CSS :enabled Example

Here is an example demonstrating use of :enabled pseudo-class. Here we see first two input boxes are enabled or active.

<html>
<head>
<style>
	input[type=text]:enabled {
		background: white;
	}

	input[type=text]:disabled {
		background: lightgrey;
	}

	input {
		width: 150px;
		padding-left: 10px;
		margin-top: 10px;
		border: 1px solid black;
	}

   form {
      border: 2px solid black;
      width: 300px;
      padding: 10px;
   }
</style>
</head>
<body>
	<h2>:enabled example</h2>
	<form action="">
      <label>First Name</label>
      <input type="text"><br>
      <label>Last Name</label>
      <input type="text"><br>
      <label>Address</label>
      <input type="text" disabled="disabled" value="Address"><br><br>
      <button type="submit" disabled="disabled">Submit</button>
      <button type="reset">Reset</button>
	</form>
</body>
</html>
Advertisements