What Does In HTML: Easy Tutorial With Code Example » (2024)

HTML/HTML Web Forms Tutorial For Coding Beginners / What Does In HTML: Easy Tutorial With Code Example

In HTML Tags

Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more

Element of
HTML Web Forms Tutorial For Coding Beginners
What does What Does In HTML: Easy Tutorial With Code Example do?
The <label> element is used to associate a text label with a form <input> field. The label is used to tell users the value that should be entered in the associated input field.
Display
inline

Code Example

<form> <label for="favorite-animal">Favorite Animal</label><br> <input name="favorite-animal" id="favorite-animal"></form>

Using Labels Properly

The <label> element is one of a handful of elements that only exists and makes sense in relationship to another element. In the case of <label>, the label has to be associated with a form field (usually in <input> element of one sort or another.

For a <label> to work properly, it must include a for attribute, which identifies the <input> to which it is associated. The for attribute’s value should match the id (not the name) of the <input> element.

(Form submission relies on name and label pairing relies on id. This is why you will often see <input> elements with the same value in both attributes. And if the <input> is a checkbox, you might see the same value in the value attribute, and as the content of the <label> element.)

<label for="first-name">First Name</label><br><input id="first-name" name="first-name">

<p>Do you agree to the terms and conditions?</p><input type="checkbox" name="agree" id="agree" value="agree"><label for="agree"> Agree</label>

Do you agree to the terms and conditions?

Labels and Usability

It is, of course, possible to not use the <label> element, and just put unmarked text over or next to a form field. But this isn’t a good idea. Having a paired label is more than just good semantics, it is good usability. With a properly marked-up label, the user can click (or finger-tap) the label in order to bring focus to the element or select it. This is moderately helpful on regular desktop and laptop computers, but on touchscreen mobile phones, it makes a huge difference.

<!-- With the label --><input type="checkbox" name="easy" id="easy" value="easy"><label for="easy"> Click this label to select.</label><br><br><!-- Without proper labelling --><input type="checkbox" name="hard" id="hard value="hard"> Can you click this label to select?

Can you click this label to select?

So, aside from basic usability, you also want to be actively working to make your website accessible to the blind and visually impaired — or anyone else who might use a screen reader to browse the internet. The association of the label to the form field allows the screen reader user to know what is obvious to a sighted a user: what words are attached to what form fields.

For more information on this topic, see our tutorial on form usability.

What Does In HTML: Easy Tutorial With Code Example » (1)

Adam is a technical writer who specializes in developer documentation and tutorials.

Browser Support for label

What Does In HTML: Easy Tutorial With Code Example » (2) What Does In HTML: Easy Tutorial With Code Example » (3) What Does In HTML: Easy Tutorial With Code Example » (4) What Does In HTML: Easy Tutorial With Code Example » (5) What Does In HTML: Easy Tutorial With Code Example » (6) What Does In HTML: Easy Tutorial With Code Example » (7)
All All All All All All

Attributes of label

Attribute name Values Notes
for
Specifies the ID of the associated form field element.
What Does In HTML: Easy Tutorial With Code Example » (2024)
Top Articles
Why Is My Zelle Payment Taking Longer Than Expected?
FedEx | System Down
Friskies Tender And Crunchy Recall
417-990-0201
Food King El Paso Ads
Tabc On The Fly Final Exam Answers
Jonathon Kinchen Net Worth
Shs Games 1V1 Lol
Linkvertise Bypass 2023
Craigslist Free Stuff Appleton Wisconsin
How To Get Free Credits On Smartjailmail
Crime Scene Photos West Memphis Three
Lesson 3 Homework Practice Measures Of Variation Answer Key
Degreeworks Sbu
123Moviescloud
General Info for Parents
Lonadine
Local Dog Boarding Kennels Near Me
How do you like playing as an antagonist? - Goonstation Forums
Michaels W2 Online
Grace Caroline Deepfake
[Birthday Column] Celebrating Sarada's Birthday on 3/31! Looking Back on the Successor to the Uchiha Legacy Who Dreams of Becoming Hokage! | NARUTO OFFICIAL SITE (NARUTO & BORUTO)
New Stores Coming To Canton Ohio 2022
Rachel Griffin Bikini
Soccer Zone Discount Code
St Maries Idaho Craigslist
How pharmacies can help
Georgia Cash 3 Midday-Lottery Results & Winning Numbers
Caring Hearts For Canines Aberdeen Nc
Troy Gamefarm Prices
Piri Leaked
Trinket Of Advanced Weaponry
Where to eat: the 50 best restaurants in Freiburg im Breisgau
My Dog Ate A 5Mg Flexeril
Cavanaugh Photography Coupon Code
Ripsi Terzian Instagram
Royal Caribbean Luggage Tags Pending
Exploring TrippleThePotatoes: A Popular Game - Unblocked Hub
Bismarck Mandan Mugshots
Toth Boer Goats
Dollar Tree's 1,000 store closure tells the perils of poor acquisitions
Anya Banerjee Feet
craigslist | michigan
Kornerstone Funeral Tulia
Nsav Investorshub
Mudfin Village Wow
Arcane Bloodline Pathfinder
Free Crossword Puzzles | BestCrosswords.com
Login
Boyfriends Extra Chapter 6
Mikayla Campinos Alive Or Dead
Phunextra
Latest Posts
Article information

Author: Twana Towne Ret

Last Updated:

Views: 5647

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Twana Towne Ret

Birthday: 1994-03-19

Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

Phone: +5958753152963

Job: National Specialist

Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.