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
About – Demian Brener – Medium
Is Non-Recourse Financing Right for You? | Commercial Real Estate Loans
Bank Of America Financial Center Irvington Photos
Tyler Sis 360 Louisiana Mo
Craigslist Home Health Care Jobs
Craigslist St. Paul
Skylar Vox Bra Size
My E Chart Elliot
Missed Connections Inland Empire
Kraziithegreat
Hawkeye 2021 123Movies
Klustron 9
Remnant Graveyard Elf
All Obituaries | Ashley's J H Williams & Sons, Inc. | Selma AL funeral home and cremation
A.e.a.o.n.m.s
Ave Bradley, Global SVP of design and creative director at Kimpton Hotels & Restaurants | Hospitality Interiors
WWE-Heldin Nikki A.S.H. verzückt Fans und Kollegen
Mills and Main Street Tour
Louisiana Sportsman Classifieds Guns
Moviesda3.Com
Pickswise Review 2024: Is Pickswise a Trusted Tipster?
Kringloopwinkel Second Sale Roosendaal - Leemstraat 4e
Vegito Clothes Xenoverse 2
Theater X Orange Heights Florida
Reborn Rich Kissasian
PCM.daily - Discussion Forum: Classique du Grand Duché
R&S Auto Lockridge Iowa
Hood County Buy Sell And Trade
Elbert County Swap Shop
The Creator Showtimes Near R/C Gateway Theater 8
8002905511
Miller Plonka Obituaries
Craigs List Jax Fl
Package Store Open Near Me Open Now
Martin Village Stm 16 & Imax
Craigslist Free Puppy
Rocksteady Steakhouse Menu
Wbli Playlist
Watchdocumentaries Gun Mayhem 2
Marine Forecast Sandy Hook To Manasquan Inlet
New York Rangers Hfboards
Craigslist Gigs Wichita Ks
Crazy Balls 3D Racing . Online Games . BrightestGames.com
How to Print Tables in R with Examples Using table()
Windshield Repair & Auto Glass Replacement in Texas| Safelite
Poe Self Chill
Celsius Claims Agent
Dyi Urban Dictionary
Heat Wave and Summer Temperature Data for Oklahoma City, Oklahoma
Bluebird Valuation Appraiser Login
Karen Kripas Obituary
Craigslist Farm And Garden Missoula
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.