HTML style using CSSLet's suppose we have created our web page using a simple HTML code, and we want something which can present our page in a correct format, and visibly attractive. So to do this, we can style our web page with CSS (Cascading Stylesheet) properties. CSS is used to apply the style in the web page which is made up of HTML elements. It describes the look of the webpage. CSS provides various style properties such as background color, padding, margin, border-color, and many more, to style a webpage. Each property in CSS has a name-value pair, and each property is separated by a semicolon (;). Note: In this chapter, we have given a small overview of CSS. You will learn everything in depth about CSS in our CSS tutorial.Example:Test it NowIn the above example, we have used a style attribute to provide some styling format to our code. Output: Welcome to javaTpointThis is a great website to learn technologies in very simple way. Three ways to apply CSSTo use CSS with HTML document, there are three ways:
Inline CSS:Inline CSS is used to apply CSS in a single element. It can apply style uniquely in each element. To apply inline CSS, you need to use style attribute within HTML element. We can use as many properties as we want, but each property should be separated by a semicolon (;). Example:Test it NowOutput: Learning HTML using Inline CSSInternal CSS:An Internal stylesheets contains the CSS properties for a webpage in <head> section of HTML document. To use Internal CSS, we can use class and id attributes. We can use internal CSS to apply a style for a single HTML page. Example:Test it NowNote: In the above example, we have used a class attribute which you will learn in the next chapter.External CSS:An external CSS contains a separate CSS file which only contains style code using the class name, id name, tag name, etc. We can use this CSS file in any HTML file by including it in HTML file using <link> tag. If we have multiple HTML pages for an application and which use similar CSS, then we can use external CSS. There are two files need to create to apply external CSS
Example:Test it NowCSS file:
body{
background-color:lavender; text-align: center; } h2{ font-style: italic; size: 30px; color: #f08080; } p{ font-size: 20px; } .blue{ color: blue; } .red{ color: red; } .green{ color: green; } Commonly used CSS properties:
Next TopicHTML Classes
|