Matt
Matt

Reputation: 750

HTML/CSS - Changing properties of a text field

Is it possible to change the properties of a text field when it's selected/active (i.e. being typed in). I'd like to simply change the border colour but I haven't found a thing about actually doing it.

I tried using :active but that only works when the mouse is pressed (obviously I guess)

Upvotes: 2

Views: 3146

Answers (3)

Dave
Dave

Reputation: 29121

To change the border of an input field when it's selected/active, use :focus

Example below:

HTML:

<input type="text" id="ageField" name="age" />

CSS:

#ageField:focus {
    border-color: #F00;
}

Explanation / Details @ W3Schools CSS:focus Selector

Upvotes: 1

Suroot
Suroot

Reputation: 4423

You are looking for the onFocus/onBlur HTML elements. With these you can use Javascript to modify the colors/style tags.

onFocus/onBlur tutorial

Upvotes: 0

user578895
user578895

Reputation:

the selector you want is called :focus

Upvotes: 5

Related Questions