created by Aha00aAha00a at 2016-08-02
last modified by Aha00aAha00a at 2016-08-02
revision: 5

Html required attribute and :invalid selector

We can fill input with error color when required field is empty using Html and Css only (without JavaScript).

Html과 Css만으로 필수 필드가 비었을 때 오류색상을 채울 수가 있다. (JavaScript를 사용하지 않고.)

괜찮구만. -- 2016-08-02

2. Sample

<h1>normal</h1>
<input type="text" placeholder="" />
<h1>required (empty)</h1>
<input type="text" required="required" />
<h1>required (not empty)</h1>
<input type="text" required="required" value="value"/>
input {
  border: 1px solid #5f5;
  background-color: #efe;
}
input[required]:invalid {
  background-color: #fee;
  border: 1px solid #f55;
}

3. See Also

3.2. Adjacent Pages

≤ 32
all
1.0x
1.0x
80
-120
ON
0/0
0/0
0.00
0
0 / 0
1.00x