WEB DEVELOPMENT SERIES(PART - 3)
This blog is a part of the web development series. If you haven’t gone through the previous parts then please go through them.
HTML STYLES
Styles in HTML are basically rules that describe how a document will be presented in a browser. Style information can be either attached as a separate document or embedded in the HTML document.
There are 3 ways of implementing style in HTML:
- Inline Style: In the this method, the style attribute is used inside the HTML start tag.
- Embedded Style: In this method, the style element is used inside the <head> element of the document.
- External Style Sheet: In this method the <link> element is used to point to an external CSS file.
Inline Style: In Inline styling, the CSS rules are directly written inside the starting tag using the style attribute. The style attribute includes a series of CSS ‘property: value’ pair is separated by a semicolon(;).
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1
style="color:Blue;font-size:25px;">
Example of Inline Style
</h1>
<p
style="color:red;">First paragraph</p>
<p
style="color:green;font-size:40px;">
Second paragraph
</p>
<hr
style="border-color:orange;">
</body>
</html>
Output:
Embedded Style: Embedded or Internal style sheets only affect the document they are embedded in. Embedded style sheets are defined in the <head> section of an HTML document using the <style> tag.
<!DOCTYPE html>
<html
lang="en">
<head>
<style
type="text/css">
body {
background-color: powderblue;
}
h1 {
color: black;
font-family: arial;
}
p {
color: yellow;
font-family: verdana;
}
</style>
</head>
<body>
<h1>Example of Embedded Style</h1>
<p>First paragraph.</p>
</body>
</html>
Output:
External Style Sheet: External Style Sheets method can be useful when the CSS has to be applied to various web pages. An external style sheet holds all the style rules in a separate document that you can link from an HTML file on your site.
There are two ways of attaching external style sheets –
- Linking External Style Sheets
- Importing External Style Sheets
Linking External Style Sheets :
In this method, an external style sheet is linked to an HTML document using the <link> tag.
<!DOCTYPE html>
<html>
<head>
<link
rel="stylesheet"
type="text/css"
href="/html/css/externalstyle.css">
</head>
<body>
<h3>Example of Linking External Style Sheet</h3>
<p>First paragraph.</p>
</body>
</html>
Output:
Importing External Style Sheets :
External style sheets can be loaded into an HTML document using “@import”. The “@import” statement instructs the browser to load the CSS file. Other CSS rules can also be included using the <style> element.
<!DOCTYPE html>
<html>
<head>
<style
type
= "text/css">
@import url("/html/css/importstyle.css");
p{color:powderblue; font - size : 30px;}
</style>
</head>
<body>
<h3>Example of external style sheet using import</h3>
<p>First paragraph</p>
</body>
</html>
Output:
Supported Browser: The browsers supported by style attribute are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
HTML TEXT FORMATTING
HTML contains several elements for defining text with a special meaning.
HTML Formatting Elements
Formatting elements were designed to display special types of text:
<b>
- Bold text<strong>
- Important text<i>
- Italic text<em>
- Emphasized text<mark>
- Marked text<small>
- Smaller text<del>
- Deleted text<ins>
- Inserted text<sub>
- Subscript text<sup>
- Superscript text
HTML <b> and <strong> Elements
The HTML <b>
element defines bold text, without any extra importance.
Example:
<b>This text is bold</b>
The HTML <strong>
element defines text with strong importance. The content inside is typically displayed in bold.
Example:
<strong>This text is important!</strong>
HTML <i> and <em> Elements
The HTML <i>
element defines a part of text in an alternate voice or mood. The content inside is typically displayed in italic.
Tip: The <i>
tag is often used to indicate a technical term, a phrase from another language, a thought, a ship name, etc.
Example:
<i>This text is italic</i>
The HTML <em>
element defines emphasized text. The content inside is typically displayed in italic.
Example:
<em>This text is emphasized</em>
HTML <small> Element
The HTML <small>
element defines smaller text:
Example:
<small>This is some smaller text.</small>
HTML <mark> Element
The HTML <mark>
element defines text that should be marked or highlighted:
Example:
<p>Do not forget to buy <mark>milk</mark> today.</p>
HTML <del> Element
The HTML <del>
element defines text that has been deleted from a document. Browsers will usually strike a line through deleted text:
Example:
<p>My favorite color is <del>blue</del> red.</p>
HTML <ins> Element
The HTML <ins>
element defines a text that has been inserted into a document. Browsers will usually underline inserted text:
Example:
<p>My favorite color is <del>blue</del> <ins>red</ins>.</p>
HTML <sub> Element
The HTML <sub>
element defines subscript text. Subscript text appears half a character below the normal line, and is sometimes rendered in a smaller font. Subscript text can be used for chemical formulas, like H2O:
Example
<p>This is <sub>subscripted</sub> text.</p>
HTML <sup> Element
The HTML <sup>
element defines superscript text. Superscript text appears half a character above the normal line, and is sometimes rendered in a smaller font. Superscript text can be used for footnotes:
Example:
<p>This is <sup>superscripted</sup> text.</p>
So, now let’s end this blog here and in next blog we will learn some more basics of HTML in brief like HTML Colors and HTML Lists.
“Until then Goodbye, Stay Safe!”