I’m trying to write code so that when I press an input field, it will highlight as yellow.
This is what I want:
(https://phpout.com/wp-content/uploads/2023/04/fR29c.png)
Here is my current html for the form:
<div class="form">
<form>
<h1 id="form-header"> Sign up for our mailing list!</h1>
Your Name:<br>
<input class="enter" type="text" name="fname"><br>
Email:<br>
<input class="enter" type="email" name="email" aria-required="true"/><br>
<button type="submit" class="submit">Submit</button>
</form>
</div>
As you can see, when you highlight the field, it’s black, and not yellow.
I tried looking up the documentation for this, but for some reason could only find code that highlights the middle portion rather than the outline. I’m also only interested in using html and CSS. If anyone could tell me how to achieve the highlight it’ll be appreciated!
4
Answers
Try adding this.
You can try the following CSS
:focus – Select & Style an input field when it gets focus
In case you want all input fields to hightlight yellow on focus you can try this css
You can achieve the desired effect by styling the input fields with CSS. When the input fields are in focus, you can highlight them with a yellow outline as shown below:
style for the input fields
style for the focused input fields
This code changes the default border color of the input fields to light gray, adds padding, and changes the font size. When an input field is in focus, that is, when the user clicks or tabs to it, the border color changes to yellow and the default blue outline is removed.
I hope this was helpful!
I’d suggest the following approach, as demonstrated in the following Snippet:
It’s worth noting that I’d also strongly suggest that you take advantage of
<label>
elements for improving the accessibility of form inputs; as the<label>
increase the touch-area, and also click-area. This has the benefit, also, of removing the<br>
elements:References:
:is
.:focus
.:focus-visible
.<button
.<fieldset>
.<input>
.<legend>
.