Home

How to Build Check Boxes for Your HTML5 and CSS3 Based Web Pages

|
Updated:  
2016-03-26 13:17:46
|
HTML5 and CSS3 All-in-One For Dummies
Explore Book
Buy On Amazon

Check boxes are a useful tool for HTML5 and CSS3 web page developers. Check boxes are used when you want the user to turn a particular choice on or off.

image0.jpg

Each check box represents a true or false value that can be selected or not selected, and the status of each check box is completely independent from the others. The user can check none of the options, all of them, or any combination.

This code shows that check boxes use your old friend the tag:

<!DOCTYPE html>
<html lang = "en-US">
 <head>
 <meta charset = "UTF-8">
 <title>checkBoxes.html</title>
 </head>
 <body>
 <form action = ">
  <fieldset>
  <legend>Please check off your life goals...</legend>
  <p>
   <input type = "checkbox"
     id = "chkPeace"
     value = "peace" />World peace
  </p>
  <p>
   <input type = "checkbox"
     id = "chkHarmony"
     value = "harmony" />Harmony and brotherhood
  </p>
  <p>
   <input type = "checkbox"
     id = "chkCash"
     value = "cash" />Cash
  </p>
  </fieldset>
 </form>
 </body>
</html>

You're using the same attributes of the tag, but they work a bit differently than the way they do in a plain old text box:

  • Theis. That's how the browser knows to make a check box, rather than a text field.

  • The checkbox still requires an ID. If you'll be writing programming code to work with this thing (and you will, eventually), you'll need an ID for reference.

  • The value is hidden from the user. The user doesn't see the actual value. That's for the programmer (like the object). Any text following the check box only appears to be the text associated with it.

About This Article

This article is from the book: 

About the book author:

Andy Harris earned a degree in Special Education from Indiana University/Purdue University–Indianapolis (IUPUI). He taught young adults with severe disabilities for several years. He also taught himself enough computer programming to support his teaching habit with freelance programming.
Those were the exciting days when computers started to have hard drives, and some computers connected to each other with arcane protocols. He taught programming in those days because it was fun.
Eventually, Andy decided to teach computer science full time, and he still teaches at IUPUI. He lectures in the applied computing program and runs the streaming media lab. He also teaches classes in whatever programming language is in demand at the time. He has developed a large number of online video-based courses and international distance education projects.
Andy has written several books on various computing topics and languages including Java, C#, mobile computing, JavaScript, and PHP/MySQL.
Andy welcomes comments and suggestions about his books. He can be reached at [email protected].