HTML - CONTROL ELEMENTS, Semantic Elements, Media Controls and HTML Api
HTML - CONTROL ELEMENTS, Semantic Elements, Media Controls and HTML Api
An HTML form is used to collect user input. The user input is most often sent to a
server for processing.
Example
First name:
John
Last name:
Doe
Submit
The HTML <form> element is used to create an HTML form for user input:
Syntax:
<form>
form elements
</form>
The <form> element is a container for different types of input elements, such as:
1. Text fields
2. Checkboxes
3. Radio buttons
4. Submit buttons
An <input> element can be displayed in many ways, depending on the type attribute.
Here are some examples:
Type Description
<input type="radio"> Displays a radio button (for selecting one of many choices)
Text Fields
The <input type="text"> defines a single-line input field for text input.
Example
<!DOCTYPE html>
<html>
<body>
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="LEELA"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="RANI">
</form>
<p>Also note that the default width of text input fields is 20 characters.</p>
</body>
</html>
First name:
Last name:
Note: The form itself is not visible. Also note that the default width of an input field is 20
characters.
Radio Buttons
Example
<!DOCTYPE html>
<html>
<body>
<h2>Radio Buttons</h2>
<p>Choose your favorite Web language:</p>
<form>
<input type="radio" id="html" name="fav_language" value="HTML">
<label for="html">HTML</label><br>
<input type="radio" id="css" name="fav_language" value="CSS">
<label for="css">CSS</label><br>
<input type="radio" id="javascript" name="fav_language" value="JavaScript">
<label for="javascript">JavaScript</label>
</form>
</body>
</html>
HTML
CSS
JavaScript
Checkboxes
Checkboxes let a user select ZERO or MORE options of a limited number of choices.
<!DOCTYPE html>
<html>
<body>
<h2>Checkboxes</h2>
<p>The <strong>input type="checkbox"</strong> defines a checkbox:</p>
<form action="/action_page.php">
</form>
</body>
</html>
The <input type="submit"> defines a button for submitting the form data to a form-handler.
The form-handler is typically a file on the server with a script for processing input data.
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called
"/action_page.php".</p>
<p>Notice that the value of the "First name" field will not be submitted, because the input
element does not have a name attribute.</p>
</body>
</html>
</form>
</form>
………………………………………………………………………………………………….
HTML tags can be categorized into two types based on semantics in HTML. They are:
Semantic Tag
Non-semantic Tag
A semantic element clearly describes its meaning to both the browser and the
developer.
<article>
<aside>
<details>
<figcaption>
<figure>
<footer>
<header>
<main>
<mark>
<nav>
<section>
<summary>
<time>
Section Element:
The <section> element defines a section in a document.
<!DOCTYPE html>
<html>
<body>
<section>
<h1>WWF</h1>
<p>The World Wide Fund for Nature (WWF) is an international organization working on
issues regarding the conservation, research and restoration of the environment, formerly named
the World Wildlife Fund. WWF was founded in 1961.</p>
</section>
<section>
<h1>WWF's Panda symbol</h1>
<p>The Panda has become the symbol of WWF. The well-known panda logo of WWF
originated from a panda named Chi Chi that was transferred from the Beijing Zoo to the London
Zoo in the same year of the establishment of WWF.</p>
</section>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<article>
<h2>Google Chrome</h2>
<p>Google Chrome is a web browser developed by Google, released in 2008. Chrome is the
world's most popular web browser today!</p>
</article>
<article>
<h2>Mozilla Firefox</h2>
<p>Mozilla Firefox is an open-source web browser developed by Mozilla. Firefox has been the
second most popular web browser since January, 2018.</p>
</article>
<article>
<h2>Microsoft Edge</h2>
<p>Microsoft Edge is a web browser developed by Microsoft, released in 2015. Microsoft Edge
replaced Internet Explorer.</p>
</article>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<article>
<header>
<h1>What Does WWF Do?</h1>
<p>WWF's mission:</p>
</header>
<p>WWF's mission is to stop the degradation of our planet's natural environment, and build a
future in which humans live in harmony with nature.</p>
</article>
</body>
</html>
authorship information
copyright information
contact information
<!DOCTYPE html>
<html>
<body>
<footer>
<p>Author: Hege Refsnes</p>
<p><a href="mailto:[email protected]">[email protected]</a></p>
</footer>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<nav>
<a href="/html/">HTML</a> |
<a href="/css/">CSS</a> |
<a href="/js/">JavaScript</a> |
<a href="/jquery/">jQuery</a>
</nav>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p>My family and I visited The Epcot center this summer. The weather was nice, and Epcot was
amazing! I had a great summer together with my family!</p>
<aside>
<h4>Epcot Center</h4>
<p>Epcot is a theme park at Walt Disney World Resort featuring exciting attractions,
international pavilions, award-winning fireworks and seasonal special events.</p>
</aside>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2>Places to Visit</h2>
<p>Puglia's most famous sight is the unique conical houses (Trulli) found in the area around
Alberobello, a declared UNESCO World Heritage Site.</p>
<figure>
<img src="rose.jpg" alt="rose" style="width:50%">
<figcaption>Fig.1 - Rose.</figcaption>
</figure>
</body>
</html>
HTML APIs
API stands for Application Programming Interface. An API is a set of pre-built programs that can
be used with the help of JavaScript. APIs are used to implement already written code to fulfill the needs
of the project you are working on.
HTML Geolocation API: The Geolocation API is used to get the current location of the user or the
page visitor. It will show the user’s location only if the user allows it to do so, as it compromises the
security and privacy of the user.
Syntax:
var loc = navigator.geolocation;
Methods available in Geolocation API:
getCurrentPosition() Method: The getCurrentPosition() method returns an object with properties
such as latitude, longitude, accuracy, altitude etc.
watchPosition() Method: This method will return the current position of the user as well as the
updated location when the position of the user changes or the user travels from one location to
another location.
clearWatch() Method: This method will stop the watchPosition() method to not tracing the user
anymore.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="container">
<h1>Hey CSE,</h1>
<h3>Welcome to CSE!</h3>
Get Location
</button>
</div>
<script>
function geoLoc() {
if (pos)
pos.getCurrentPosition(getLoc);
else
function getLoc(loc) {
+ loc.coords.latitude +
"<br>Longitude: " +
loc.coords.longitude;
</script>
</body>
</html>
HTML 5 Media controls
You can use to control video either declaratively, through static HTML, or dynamically, using JavaScript.
First, you need to examine the key attributes available to use on the <video> element as listed in the
Atribute Description
src This attribute specifies the video to play. It can be a local resource within your
own website or something exposed through a public URL on the Internet.
autoplay This attribute tells the browser to start playing the video as soon as it loads. If
this attribute is omitted, the video plays only when told to through player
controls or JavaScript.
controls This attribute tells the browser to include its built-in video controls, such as
play and pause. If this is omitted, the user has no visible way to play the
content. You would use autoplay or provide some other mechanism through
JavaScript to play the video.
height/width These attributes control the amount of space the video will occupy on the page.
Omitting these causes the video to display in its native size.
For audio,
<audio src = "foo.wav" controls autoplay>
Your browser does not support the <audio> element.
</audio>
For video,
<video src = "foo.mp4" width = "300" height = "200" controls>
Your browser does not support the <video> element.
</video>
EXAMPLE:
<!DOCTYPE html>
<html>
<body>
<p>
Video courtesy of
<a href="https://www.bigbuckbunny.org/" target="_blank"><strong>Nature</a>.
</body>
</html>
<!DOCTYPE html>
<html>
<body>
</body>
</html>