Pseudo-classes for Form Element

CSS3 introduced some new pseudo-classes for form elements. In this video tutorial we’ll be looking at these 3 pseudo-classes:
:required
:valid
:invalid

required-fields-css3-html5

HTML file
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
< !DOCTYPE HTML>
<html>
<head>
<title>CSS pseudo-classes for form elements</title>
<meta charset="utf-8"/>
<link href="myStyle.css" rel="stylesheet"/>
</head>
<body>
 
<form>
Text: <input type="text" required/><br />
Email: <input type="email" placeholder="[email protected]"/><br />
<input type="submit" value="done!"/>
</form>
 
</body>
</html>

Here we have attached a stylesheet where we write css3 form element pseudo-class definition. Here we also take 2 input fields of type text and email respectively. We also make the text field as required. Also add a placeholder to the email input field to provide hint to the user.

CSS file
myStyle.css

1
2
3
4
5
6
7
8
9
10
11
input:required {
background-color: yellow;
}
 
input:valid {
background-color: lightblue;
}
 
input:invalid {
background-color: red;
}

Here the fields which has been specified as required will get a background-color of yellow. valid entries will have a lightblue input field background color, and invalid entry input fields background turns red color.

CSS3 pseudo-classes For Form Element: HTML5


[youtube https://www.youtube.com/watch?v=Yw5s0G1uQoA]

YouTube Link: https://www.youtube.com/watch?v=Yw5s0G1uQoA [Watch the Video In Full Screen.]



Note:
CSS3 introduces new form elements like email, number, date etc ..all these fields validate themselves. We need not write lengthy JavaScript code to make small validations – like, checking if the user entered numeric value in the input field marked as age. Since age input field will have a numeric input type, if the user enters any string, we can let the user know about the wrong entry by making use of these css3 introduced pseudo-classes.

Also note that, if you try to submit the form without filling the required fields, you’ll get a little tool tip like message interface, telling you to fill the form field.

HTML5 – Getting Started Guide

This video tutorial teaches how to start with HTML5.
Some basic changes that you need to know before starting to learn HTML5.

Technologies involved to learn HTML5:
Javascript API.
CSS3.
HTML5.

html5-features

Some of the things we’ll be learning throughout this course:
New Elements
New Attributes
CSS3 Selectors
Rounded Corners
Shadow Effects
Video and Audio
2D/3D Graphics
Local Storage
offline caching
web workers
Drag and Drop
Geolocation
Working with Google Maps API.
Forms
Sockets
Canvas ..etc

HTML5 File
index.html

1
2
3
4
5
6
7
8
9
10
< !doctype html>
<html>
 <head>
  <title>HTML5 Tutorials: from Technotip</title>
  <meta charset="UTF-8"/>
 </head>
 <body>
  <p>This is a video tutorial sponsored by or produced by Technotip.com</p>
 </body>
</html>

Doctype: no more Googling or copy pasting or relying on your fancy text editors to get the clumsy looking doctypes. With HTML5, the doctype has been simplified and is easy to remember.

Doctypes for HTML6, HTML7 ?
The doctype will stay the same for HTML5, HTML6, HTML7, HTML8, HTML9, HTML10, HTML11, HTML12 etc :-) This is a promise from W3C.

Previous HTML versions(like xHTML, HTML4, HTML4.0.1 etc) depended on SGML, but HTML5 and onwards it doesn’t depend on SGML. When the browser parses the first line(i.e., the doctype of HTML5), it’ll execute in HTML5 standards mode.

By using a doctype the browser is able to be more precise in the way it interprets and renders your pages. If you don’t specify any doctype, it still works, but it may cause the browser to render things wrongly. And it may take more time for the browser to fail gracefully, after trying to figureout all possible ways to parse the tags and to try its best to present your web pages properly.

Meta tag
It has also been simplified and now, only character set information is enough.

CSS – Cascading Stylesheet

1
 <link rel="stylesheet" href="style.css"/>

In HTML5 there is no need to write the type attribute with link tag.
Because CSS has been declared as the standard and default style for HTML5.

JavaScript

1
 <script src="myScript.js"></script>

In HTML5 there is no need to write the type attribute with script tag.
Because JavaScript has been declared as the standard and default scripting language for HTML5.

Embeded JavaScript

1
2
3
 <script>
var name = "Technotip.com";
 </script>

If you’re writing embeded javascript, then you can simply start with a opening script tag and a closing script tag. Here too, you need not specify the type attribute.

Introduction To HTML5


[youtube https://www.youtube.com/watch?v=cBW5PUiAG7s]

YouTube Link: https://www.youtube.com/watch?v=cBW5PUiAG7s [Watch the Video In Full Screen.]



Upgrade your web pages to HTML5
To upgrade your web pages to HTML5 standards, simply make these small changes:
1. doctype.
2. remove type attribute from link and script tags.
3. remove and if needed replace deprecated tags(will discuss in coming video tutorials) from your website.

Use validator.w3.org tool to check your webpage.