2

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)

3 Answers 3

5

the selector you want is called :focus

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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

onFocus/onBlur tutorial

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.