Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7594761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:30:05+00:00 2026-05-30T21:30:05+00:00

I see all over the web two ways that people code checkboxes, which one

  • 0

I see all over the web two ways that people code checkboxes, which one is correct?

  1. <input id="a" type="checkbox"/><label for="a">checkbox</label>
  2. <label for="b"><input id="b" type="checkbox">checkbox</label>

They both work fine in Chrome, is one more cross browser than the other? Is there any difference?

DEMO

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:30:06+00:00Added an answer on May 30, 2026 at 9:30 pm

    Both are perfectly correct, valid and accessible as long as you associate input and label with for/id attributes, even when the input is right into the label` (see the best answer to the question linked by @AramKocharyan and my comment there)

    Screen readers will read the associated label content when its user focus on a form element (input, select or textarea). When in a form, chances are they’ll only read labels, legends and buttons (I mean reset, submit, image or button) because JAWS and alike have special modes; roughly the aim is to fill a form, not to read the content as with the rest of a web page.

    You’ll often find forms with a label on the left, input on center and some help on the right:

            E-mail [                 ] ex: johndoe@domain.com
    
    • With an input outside the label element, the hint will be coded with a span for example. It won’t be heard by screen readers because it’s not part of a label or submit button.
    • With an input inside a label element, you can put both the label and the hint into the label element:

      <label for="email">
          <strong>E-mail</strong>
          <input type="text" id="email" name="whatever"> <!-- HTML4.01 doctype -->
          <span>ex: johndoe@domain.com</span>
      </label>
      

    That way, the hint will be read to the AT user along with the real label.
    Note: of course you’ll style the strong and span differently, say resp. bold right-aligned and italic left-aligned. span isn’t necessary for styling (just style label and cancel half of rules for strong) but it’s more simple (simpler?) 🙂

    It’s as useful for errors as for hints:

        <p class="error>
            <label for="email">
                <strong>E-mail</strong>
                <input type="text" id="email" name="whatever" value="aaa"> <!-- HTML4.01 doctype -->
                <span>ERROR: not a valid e-mail address. Example of a valid e-mail: johndoe@domain.com</span>
            </label>
        </p>
    

        .error strong {
          color: red;
          font-weight: bold;
        }
    
        .error input {
          border: 1px solid red;
        }
    
        .error span {
          color: red;
        }
    

    That way, the error is read to screen readers (and color that they can’t see or barely see isn’t the only way of conveying information to them with the help of this text).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see code like this all over the web var days= Monday Tuesday Wednesday
I see JRE all over the place, but i can not be sure which
All over the web, I am getting the feeling that writing a C backend
I'm trying to create a web form that contains checkboxes, among other input elements,
I see some frameworks like Django using unicode all over the place so it
I've been searching all over the place and just don't see anyone doing it
I want to see all the different ways you can come up with, for
I would like to see all revision numbers that made any changes to a
How can I see all the records that appear more than once per day?
My over all goal is to upload a very simple ASP.NET web site created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.