Start learning with our library of video tutorials taught by experts. Get started

HTML Essential Training

Using text elements


From:

HTML Essential Training

with Bill Weinman

Video: Using text elements

In HTML5, the number of different types of text elements for forms has grown. Only a few are supported in all the browsers, but it's worthwhile to take a look at those we can. Let's make a working copy of text-elements.html, and I am going to name this text-elements-working.html, and I am going to open it in my text editor here. And you'll see we have our style sheet and JavaScript we are using throughout this chapter. And here we have our forms element, and at the bottom, it's just as it is in the rest of the chapter.
Expand all | Collapse all
  1. 5m 24s
    1. Welcome
      56s
    2. Using the exercise files
      1m 37s
    3. What you need to know about this course
      2m 51s
  2. 22m 0s
    1. What is HTML?
      4m 12s
    2. Examining the structure of an HTML document
      7m 50s
    3. Understanding tags and containers
      6m 4s
    4. Exploring content models in HTML5
      2m 23s
    5. Looking at obsolete elements
      1m 31s
  3. 27m 19s
    1. Understanding whitespace and comments
      3m 53s
    2. Displaying text with paragraphs
      3m 37s
    3. Applying style
      8m 5s
    4. Using block and inline tags
      6m 34s
    5. Displaying characters with references
      5m 10s
  4. 16m 36s
    1. Exploring the front matter of HTML
      2m 9s
    2. Applying CSS to your document
      3m 59s
    3. Adding scripting elements
      4m 54s
    4. Using the meta tag
      3m 34s
    5. Optimizing your page for search engines
      2m 0s
  5. 24m 59s
    1. Controlling line breaks and spaces
      2m 46s
    2. Exploring phrase elements
      1m 44s
    3. Using font markup elements
      1m 5s
    4. Highlighting text with mark
      1m 29s
    5. Adding headings
      1m 38s
    6. Using quotations and quote marks
      3m 2s
    7. Exploring preformatted text
      1m 45s
    8. Formatting lists
      2m 28s
    9. Forcing text direction
      3m 49s
    10. Suggesting word-break opportunities
      2m 29s
    11. Annotating East Asian languages
      2m 44s
  6. 29m 15s
    1. Introducing CSS
      55s
    2. Understanding CSS placement
      6m 55s
    3. Exploring CSS syntax
      10m 34s
    4. Understanding CSS units of measure
      3m 3s
    5. Some CSS examples
      7m 48s
  7. 22m 5s
    1. Using images
      4m 13s
    2. Flowing text around an image
      4m 55s
    3. Breaking lines around an image
      3m 3s
    4. Aligning images
      5m 25s
    5. Mapping links in an image
      4m 29s
  8. 22m 28s
    1. Understanding URLs
      2m 41s
    2. Working with hyperlinks
      3m 28s
    3. Using relative URLs
      4m 20s
    4. Specifying a base URL
      2m 19s
    5. Linking within a page
      4m 12s
    6. Using image links
      5m 28s
  9. 17m 2s
    1. Exploring list types
      3m 52s
    2. List elements in depth
      7m 44s
    3. Using text menus with unordered lists
      5m 26s
  10. 15m 30s
    1. Introduction to HTML semantics
      4m 9s
    2. Exploring an example
      4m 56s
    3. Marking up figures and illustrations
      2m 33s
    4. Creating collapsible details
      3m 52s
  11. 11m 18s
    1. Embedding audio
      5m 19s
    2. Embedding video
      5m 59s
  12. 11m 53s
    1. Creating ad-hoc Document Object Model (DOM) data with the data-* attribute
      4m 53s
    2. Displaying relative values with meter
      2m 57s
    3. Creating dynamic progress indicators
      4m 3s
  13. 4m 49s
    1. Overview of HTML5 microdata
      1m 8s
    2. Exploring an example with microdata
      3m 41s
  14. 7m 3s
    1. Understanding outlines
      52s
    2. A demonstration of outlining
      6m 11s
  15. 13m 1s
    1. Table basics
      7m 29s
    2. Exploring the semantic parts of a table
      2m 32s
    3. Grouping columns
      3m 0s
  16. 9m 55s
    1. Frames overview
      54s
    2. Using traditional frames
      4m 26s
    3. Exploring inline frames using iframe
      2m 7s
    4. Simulating frames with CSS
      2m 28s
  17. 53m 7s
    1. Introducing forms
      10m 24s
    2. Using text elements
      10m 12s
    3. Using checkboxes and radio buttons
      2m 37s
    4. Creating selection lists and dropdown lists
      5m 14s
    5. Submit and button elements
      8m 48s
    6. Using an image as a submit button
      2m 15s
    7. Keeping context with the hidden element
      3m 0s
    8. Setting tab order
      2m 7s
    9. Preloading an autocomplete list using the datalist feature
      5m 26s
    10. Displaying results with output
      3m 4s
  18. 19m 47s
    1. Touring a complete site
      2m 14s
    2. Touring the HTML
      8m 44s
    3. Touring the CSS
      8m 49s
  19. 29s
    1. Goodbye
      29s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
HTML Essential Training
5h 34m Beginner Sep 11, 2012

Viewers: in countries Watching now:

This course introduces web designers to the nuts and bolts of HTML (HyperText Markup Language), the programming language used to create web pages. Author Bill Weinman explains what HTML is, how it's structured, and presents the major tags and features of the language. Discover how to format text and lists, add images and flow text around them, link to other pages and sites, embed audio and video, and create HTML forms. Additional tutorials cover the new elements in HTML5, the latest version of HTML, and prepare you to start working with Cascading Style Sheets (CSS).

Topics include:
  • What is HTML?
  • Using HTML tags and containers
  • Understanding block vs. inline tags
  • Controlling line breaks and spaces in text
  • Aligning images
  • Linking within a page
  • Using relative links
  • Working with tables
  • Creating progress indicators with HTML5
  • Adding buttons and check boxes to forms
  • Applying CSS
  • Optimizing your pages for search engines
  • Building document outlines
Subjects:
Developer Web Web Foundations Web Development
Software:
HTML
Author:
Bill Weinman

Using text elements

In HTML5, the number of different types of text elements for forms has grown. Only a few are supported in all the browsers, but it's worthwhile to take a look at those we can. Let's make a working copy of text-elements.html, and I am going to name this text-elements-working.html, and I am going to open it in my text editor here. And you'll see we have our style sheet and JavaScript we are using throughout this chapter. And here we have our forms element, and at the bottom, it's just as it is in the rest of the chapter.

In our form, we have a number of different elements. So let's go ahead and bring this us up in the browser, and I am going to start by bringing it up in Chrome so you can see what all of these are supposed to look like, because it actually implements all of these. And I am also going to bring it up in Firefox, so you can see what it looks like there where a lot of these elements are not implemented. Most of these elements are implemented with the input tag, and the input tag in HTML is overloaded with a lot of different types of form elements.

The default is text, and so if I actually take this out and save this and just say input name ="text1" autofocus, and I reload this in my browser, you see I still have that text element. So what's interesting about that fact is that for one of these elements, like for instance the date element, which is supported in Chrome, but not in Firefox, is that it simply defaults to a regular text element, and I can type whatever I want in there.

So the default is type="text" and if you put in a type that is not supported, the standard says you're supposed to default to text--and that's exactly what every browser I've ever seen does. And so with all of these different types that are--new, date, color, email, number, range, search--it just defaults to text. So most of these are not supported in Firefox, so they just come up as text elements. Each of these has a name, and you can also give it a value.

If I say here value="foo", that gives it a default value. So when I bring it up--I am going to stick with Chrome here for a while, but it works the same in Firefox-- when I reload this, you see it has that foo value in it. And it still gets the autofocus, because I have the autofocus attribute here. And that default value, if I press the Return key on my keyboard, it will go ahead and submit the form of the JavaScript. You see that that value is what comes up there in the text1 field. So the name is text1, and the value is whatever you type into it.

If I type something else into it here, you see that that value comes up as what I typed in. So we'll go ahead and take that out. We will look at the password field here. So we have type="password" and name="password1". And so the difference with a password field is when you type into it, what you are typing is obscured. And when I press Return, that value actually gets sent to whatever process it is. If it's JavaScript or if it's CGI, that value gets sent so that it can process that value and check the password or do whatever it's going to do with it. Input type="date".

Now I've done a few things here. Type="date" has a datepicker and so in Google Chrome, I can actually--there is the month, so I can select a different month from the dropdown. It's got this whole datepicker thing; here's different years. And I select one, and there is February 11, 2015. Notice that it's formatting it according to the locale in my system setting for my computer, so it will do that. Actually, on my laptop, I've changed the setting for this so it shows year, month, day because I am a programmer, and I like to be really specific, and this to me is really vague.

If you're in Europe, it will probably be month, day, year as opposed to day, month, year, how we have here. But on Firefox you will notice that it just comes out as a regular text field, because Firefox doesn't support that. So this gives me an opportunity to show you another feature. If I type something in here that is not a date and I submit it, you notice that I get a little error that says, "Please match the requested format: YYYY-MM-DD," and that's because here in the code, I've put in this pattern. Pattern is a new attribute in HTML5 that allows you to use a regular expression to give it a pattern for what sort of input is expected, and then the validation API will actually check it against that pattern.

And I use the title attribute so that I have a little tooltip that says this is the format that's expected there. So now if I type in an actual date, you notice that as soon as that is matching, that the little red outline goes away. If I put in too many then I get the red outline again, and when I enter that I now get the valid. So it makes the validation easier is all that that is. That's just an interface to the validation API. Next up is the color element, and so we have type="color", name="color1", and I gave it a value here for a starting color.

And so when I bring this up in Google Chrome and I reload, you notice that that bluish color, that's the color that I specified here, 369 in hex. And if I change this and I like this little reddish color there and now when I submit the form--press the Big Red Button--you notice that our color is aa1723. That's the color that I selected from the color picker. And of course on whatever platform you're testing this on, your color picker will be different. That's the Mac color picker, so it's just interfacing into the operating system to get whatever color picker is available there.

The email element, this actually works on both of these platforms. If I type something in here that is not an email address, I will get a little error. It's just a validation thing. It says, "Please enter a comma-separated list of email addresses." And you'll notice that I have here the multiple attribute. If I take that out and I save and I reload over here and I type in an invalid email address, it will say, "Please enter an email address." If I try to enter actually a valid email address, because X is a valid domain--it's just isn't one that actually exists on the Internet, but it could exist on my local network.

I could set up a local DNS server and make that work. And so that's a valid email address, and that validates. If I put in here ,y@y, that's not a valid email address. But if I come back here and put back in the multiple attribute, now that's accepted. If I reload here and say x@x, y@y, it now validates. And you notice it even took out the space, and that's making it easier for my remote process to parse that. Next up is the number type. This has a number and I gave it min="1" max="5" value="1".

And that gives me a little number chooser here on Google Chrome. And on Firefox it's just a text field, and it doesn't validate as number, and I can put in Xs here and it validates just fine. That's not implemented in Firefox. And this number chooser, you notice that it implements my minimum and maximum. It won't let me go below one, and it won't let me go above 5. Likewise, the range, this is the range type, and it gives me this range chooser here, and you notice that it's in steps of 10. I have min="0" max="100" step="10" value="20".

So it starts out at 20, which is right about there, and if I wanted to, I could put in some JavaScript over here that would show the value. And if I change this to all the way maximum, press the Big Red Button, then I get 100. If I put it down a couple of notches, I'll get 80. If I change this step="1" or take it out altogether, save that, and reload, now you see it's continuous, and it doesn't step like that. And if I press the Big Red Button--I happened to hit a round number there, didn't I? But I can get any number that I want here.

That range element is also not implemented in Firefox. The search element is really just like a text field, only it's formatted to look like a search box. So if I type something in here, it's formatted according to whatever the operating system has for a search box widget. It's even got that little X there for deleting what's there. And that's implemented in Chrome, and it's not implemented in Firefox at all. The URL element is just like a textbox, only it validates as a URL.

So if I just put in foo bar baz, it'll say Please enter a URL. So I have to put in a valid URL. I can say this is my website and it will accept that. Or actually any valid URL-- which of course even x:x is a valid URL. And this also is implemented in Firefox. So if I say foo bar baz, this is easy to implement because it's just a validation routine. And again, x:x. And the HTML specification even gives an algorithm for validating this stuff, so it makes it really easy.

And finally, text area, this is an element that's been around since the very beginning, and so of course it's implemented equally everywhere. foo bar baz, and I can just paste a bunch of those in, and it goes on and on and on, and I can press the Big Red Button. I got this big bunch of text there. And that's what the text area is for, and that works just exactly the same in pretty much any browser. They are formatted a little differently here. You notice that in Chrome it's got the same font as the rest of the elements. In Firefox this is an old tradition.

These used to always be formatted as monospace text. And so Firefox still does that for traditional reasons. You are going to want to style all of this stuff in real life. So those are the text elements. There are actually a lot more of them, and not all of them are implemented yet in any of the browsers I've tested, and some of them only work in a limited number of browsers. So I would consider most of these new ones to be experimental, with the exception of text, password, and text area. If you need your forms to work well in a variety of environments, I suggest you test it well or limit yourself to just the text and password and text area elements and perhaps the email element for now.

Find answers to the most frequently asked questions about HTML Essential Training.


Expand all | Collapse all
Please wait...
Q: The horizontal nab bar built in Chapter 8 doesn't work correctly in Internet Explorer 8. Do you have a solution?
A: Internet Explorer 8 does not support HTML5 and the NAV element.

The nab bar can work in IE 8 if you change the nav element to div, and update the CSS accordingly. You will also need to move the "display: inline" from the "ul.menu li a" rule to the "ul.menu li" rule.
Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed HTML Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked