Exp4 HTML
Exp4 HTML
Aim: - To create an html file by applying the different styles using inline,
external & internal style sheets.
Theory:-
Cascading Style Sheets (CSS) is a markup language responsible for how your web pages
will look like. It controls the colors, fonts, and layouts of your website elements.
This style sheet language also allows you to add effects or animations to your website.
You can use it to display some CSS animations like click button effects, spinners or
loaders, and animated backgrounds.
Without CSS, your website will appear as a plain HTML page.
Internal CSS
Internal or embedded CSS requires you to add a <style> tag in the <head> section of
your HTML document.
This CSS style is an effective method of styling a single page. However, using this style
for multiple pages is time-consuming as you need to put CSS rules on every page of
your website.
Here’s how you can use internal CSS:
</style>
Adding the code to the HTML document can increase the page’s size and loading
time.
External CSS
With external CSS, you’ll link your web pages to an external .css file, which can be
created by any text editor in your device (e.g., Notepad++).
This CSS type is a more efficient method, especially for styling a large website. By
editing one .css file, you can change your entire site at once.
Follow these steps to use external CSS:
1. Create a new .css file with the text editor, and add the style rules. For example:
.xleftcol {
float: left;
width: 33%;
background:#809900;
}
.xmiddlecol {
float: left;
width: 34%;
background:#eff2df;
}
Since the CSS code is in a separate document, your HTML files will have a
cleaner structure and are smaller in size.
You can use the same .css file for multiple pages.
Your pages may not be rendered correctly until the external CSS is loaded.
Uploading or linking to multiple CSS files can increase your site’s download
time.
Inline CSS
Inline CSS is used to style a specific HTML element. For this CSS style, you’ll only
need to add the style attribute to each HTML tag, without using selectors.
This CSS type is not really recommended, as each HTML tag needs to be styled
individually. Managing your website may become too hard if you only use inline CSS.
However, inline CSS in HTML can be useful in some situations. For example, in cases
where you don’t have access to CSS files or need to apply styles for a single element
only.
Let’s take a look at an example. Here, we add an inline CSS to the <p> and <h1> tag:
<!DOCTYPE html>
<html>
<body style="background-color:black;">
<h1 style="color:white;padding:30px;">Hostinger Tutorials</h1>
<p style="color:white;">Something usefull here.</p>
</body>
</html>
Advantages of Inline CSS:
You can easily and quickly insert CSS rules into an HTML page. That’s why this
method is useful for testing or previewing the changes and performing quick
fixes to your website.
You don’t need to create and upload a separate document as in the external style.
Adding CSS rules to every HTML element is time-consuming and makes your
HTML structure messy.
Styling multiple elements can affect your page’s size and download time.
Basic syntax:
selector {property:value;
property:value; …..} selector =>
identifier of the element
e.g.
body {background : yellow; color : yellow}
p {font-family: “Times New Roman”;
font-size: 14px} h1,h3 {color : red}
Class:
selector.class-
name{property:value;
property:value} e.g.
1. p.right{text-align: right} use in HTML document:
<p class=”right”> Here is some text </p>
.left {color : blue} use in HTML document:
<p class=”left”> Here is some text </p>
<h3 class=”left”> Here is another text </h3>
1. Create a css file in a notepad & save it with the .css extension.
2. In notepad type the necessary code & save with the file name mentioned with .html
extension.
<p> CSS stands for Cascading Style Sheets. Styles define how to display
HTML elements. CSS Saves a Lot of Work! CSS defines HOW HTML
elements are to be displayed.
</p>
</div>
</div>
<p style="border-style:dotted solid dashed double">This is some text in a para.</p>
<p style="border-style:dotted solid dashed">This is some text in a paragra.</p>
<p style="border-style:dotted solid">This is some text in a paragraph.</p>
<p style="border-style:dotted">This is some text in a paragraphsss.</p>
<h2>This is a header 1</h2>
<hr />
<p>You can see that the style sheet formats the text</p>
<p><a href="http://www.google.co.in/" target="_blank">This is a link</a></p>
</body>
</html>
Output :-