Professional Documents
Culture Documents
Web CH 2 - Part 3
Web CH 2 - Part 3
Web CH 2 - Part 3
• Multiple HTML elements can share the <p>London is the capital of England.</p>
</div>
<h1>My <span class="note"
>Important</span> Heading
same class. <div class="city"> </h1>
<h2>Paris</h2> <p>This is
• The class attribute is often used to point to a <p>Paris is the capital of France.</p>
</div>
some <span class="note">i
mportant</span> text.</p>
class name in a style sheet and also be used <div class="city">
<h2>Tokyo</h2>
by a JavaScript to access and manipulate <p>Tokyo is the capital of Japan.</p> </body>
</div> </html>
elements with the specific class name.
</body>
</html>
2
Compiled By Aliazar D. (MSc in SEng)
Conti.. <!DOCTYPE html>
<html>
• Use of The class Attribute in
JavaScript
<head>
• The class name can also be
• Multiple Classes <style>
used by JavaScript to perform
.city {
✓ HTML elements can background-color: tomato;
certain tasks for specific
elements.
belong to more than color: white;
one class. padding: 10px;
• JavaScript can access elements
}
✓ To define multiple with a specific class name with
the getElementsByClassName()
classes, separate the .main { method:
text-align: center;
class names with a }
space, e.g. <div </style>
<script>
class="city main">. </head> function myFunction() {
The element will be <body> var x
• The id attribute is used to text-align: center; /* Style all elements with the class name "city"
*/
point to a specific style } .city {
background-color: tomato;
declaration in a style sheet. </style> color: white;
padding: 10px;
</head>
• It is also used by JavaScript to <body>
}
</style>
• HTML contains several elements for defining user input and computer code.
• The HTML <kbd> element is used to define keyboard input. The content
inside is displayed in the browser's default monospace font. <p>Save the
document by pressing <kbd>Ctrl + S</kbd></p>
• The HTML <samp> element is used to define sample output from a
computer program.
• The HTML <code> element is used to define a piece of computer code.
The content inside is displayed in the browser's default monospace font.
• The HTML <var> element is used to define a variable in programming or
in a mathematical expression. The content inside is typically displayed in
italic.
12
<time> Defines a date/time Compiled By Aliazar D. (MSc in SEng)
HTML Entities
Result Description Entity Entity
Name Number
• Some characters are reserved in HTML. non-breaking space  
• Reserved characters in HTML must be < less than < <
replaced with character entities.
> greater than > >
• If you use the less than (<) or greater than (>)
signs in your text, the browser might mix & ampersand & &
• To display a less than sign (<) we must write: € euro € €
✓ 😍 is 128525 😏
😐
128527
128528
1F60F
1F610
✓ 💗 is 128151 😑 128529 1F611
😒 128530 1F612
😓 128531 1F613
for different types of input elements, <input type="submit"> Displays a submit button
(for submitting the form)
such as: text fields, checkboxes, <input type="button"> Displays a clickable button
radio buttons, submit buttons, etc.
16
Compiled By Aliazar D. (MSc in SEng)
Conti..
<!DOCTYPE html>
<html>
<body>
Text Fields • The <label> Element <h2>Radio Buttons</h2>
✓ The <input type="text"> ✓ The <label> tag defines a <p> Choose your favorite Web
defines a single-line input field label for many form language:</p>
<form>
for text input. elements.
<!DOCTYPE html> <input type="radio" id="html" name
✓ The <label> element is ="fav_language" value="HTML">
<html> useful for screen-reader <label for="html">HTML</label><br>
<body> <input type="radio" id="css" name=
users. "fav_language" value="CSS">
<h2>Text input fields</h2> ✓ The for attribute of the <label for="css">CSS</label><br>
<form> <input type="radio" id="javascript
<label> tag should be equal " name="fav_language" value="JavaScr
<label for="fname">First to the id attribute of the ipt">
name:</label><br> <label for="javascript">JavaScript
<input> element to bind </label>
<input type="text" id="fname"
name="fname" value="Lazarus"><br> them together.
</form>
<label for="lname">Last </body>
name:</label><br> • Radio Buttons </html>
Selection vs Datalist
Generally, both the tags are used for choosing an option from
the given list. But the main difference between both is that in
the <datalist> tag the user can enter its own input and add that
as an option with the help of the <input> element whereas the
<select> tag doesn't provide this feature.
21
Compiled By Aliazar D. (MSc in SEng)
•
HTML Input Types • Input Type Checkbox
✓ <input type="checkbox"> ✓
Input Type Email
The <input
• Input Type Text type="email"> is
• defines a checkbox.
Here are the different ✓ <input type="text">
input types you can use in • Input Type Button used for input fields
defines a single-line text
HTML: ✓ <input type="button"> that should contain
input field.
•<input type="button"> defines a button. an e-mail address.
•<input type="checkbox"> • Input Type Password
• Input Type Color • Input Type Image
•<input type="color"> ✓ <input type="password">
✓ The <input type="color"> ✓ The <input
•<input type="date"> defines a password field type="image">
is used for input fields that
•<input type="datetime-local">• Input Type Submit defines an image as
•<input type="email"> should contain a color.
✓ <input type="submit">
•<input type="file"> • Input Type Date a submit button.
defines a button for
•<input type="hidden"> ✓ The <input type="date"> • Input Type File
submitting form data to a
•<input type="image"> is used for input fields that ✓ The <input
form-handler.
•<input type="month"> should contain a date. type="file"> defines
•<input type="number"> • Input Type Reset
• Input Type Datetime- a file-select field
•<input type="password"> ✓ <input type="reset">
local and a "Browse"
•<input type="radio"> defines a reset button that
• The <input button for file
•<input type="range"> will reset all form values uploads.
•<input type="reset"> type="datetime-local">
to their default values.
•<input type="search"> specifies a date and time • Input Type Month
• Input Type Radio
•<input type="submit"> input field, with no time • The <input
✓ <input type="radio"> type="month">
•<input type="tel"> zone.
defines a radio button.
•<input type="text"> allows the user to
•<input type="time"> select a month and
•<input type="url"> year.
Compiled By Aliazar D. (MSc in SEng) 22
•<input type="week">
Conti..
• Input Type Number
• The <input type="number"> defines a numeric input field.
• Input Type Range
✓ The <input type="range"> defines a control for entering a number whose exact
value is not important (like a slider control).
• Input Type Search
✓ The <input type="search"> is used for search fields (a search field behaves like a
regular text field).
• Input Type Tel
✓ The <input type="tel"> is used for input fields that should contain a telephone
number.
• Input Type Time
✓ The <input type="time"> allows the user to select a time (no time zone).
• Input Type Url
✓ The <input type="url"> is used for input fields that should contain a URL
address.
• Input Type Week
23
✓ The <input type="week"> allows the user to select a week and year. Compiled By Aliazar D. (MSc in SEng)
HTML Input Attributes
• The value Attribute • The multiple Attribute • The step Attribute
✓ The input multiple attribute ✓ The input step attribute specifies
✓ The input value attribute specifies an
initial value for an input field. specifies that the user is allowed the legal number intervals for an
to enter more than one value in an input field.
• The readonly Attribute
input field. • The autofocus Attribute
✓ The input readonly attribute specifies ✓ The multiple attribute works with ✓ The input autofocus attribute
that an input field is read-only.
the following input types: email, specifies that an input field should
• The disabled Attribute and file. automatically get focus when the
✓ The input disabled attribute specifies • The input pattern attribute page loads.
that an input field should be disabled. ✓ Specifies a regular expression that ✓ The height and width
• The size Attribute the input field's value is checked Attributes
✓ The input size attribute specifies the against, when the form is • The input height and width
visible width, in characters, of an input submitted. attributes specify the height and
field. The default value for size is 20. ✓ The pattern attribute works with width of an <input
• The maxlength Attribute the following input types: text, type="image"> element.
✓ The input maxlength attribute specifies date, search, url, tel, email, and • The list Attribute
the maximum number of characters password. ✓ The input list attribute refers to a
allowed in an input field. • The placeholder Attribute <datalist> element that contains
• The min and max Attributes ✓ The input placeholder attribute pre-defined options for an
• The input min and max attributes specifies a short hint that <input> element.
specify the minimum and maximum describes the expected value of an • The autocomplete Attribute
values for an input field. input field (a sample value or a ✓ The input autocomplete attribute
• The min and max attributes work with short description of the expected specifies whether a form or an
the following input types: number, format). input field should have
range, date, datetime-local, month, time
and week. autocomplete on or off.
24
Compiled By Aliazar D. (MSc in SEng)
HTML Input form* Attributes
• The input form attribute
✓ Specifies the form the <input> element belongs to.
✓ The value of this attribute must be equal to the id attribute of the <form> element it
belongs to.
• The formaction Attribute
✓ The input formaction attribute specifies the URL of the file that will process the input
when the form is submitted.
• The formenctype Attribute
✓ The input formenctype attribute specifies how the form-data should be encoded when
submitted (only for forms with method="post").
• The formmethod Attribute
✓ The input formmethod attribute defines the HTTP method for sending form-data to the
action URL.
• The formnovalidate Attribute
✓ The input formnovalidate attribute specifies that an <input> element should not be
validated when submitted.
• The novalidate Attribute
✓ The novalidate attribute is a <form> attribute.