M1
In this assignment, I will be discussing the different implementation styles of CSS in a HTML file. CSS stands for Cascading Style Sheet where the developer codes the website to present in a certain way. However, there are three types of implementation of CSS . These are:-
- Inline
- Embedded
- External
Inline
This is the first implementation style of CSS. In an inline style of CSS, the CSS is used on the same HTML document and every tag has its own CSS implementation. The CSS is added to the same line as the HTML, which requires its manipulations that the user requires to be done individually, for each piece of content on the webpage. Every HTML tag is given a CSS statement which means that it has been styled using CSS. I have shown an example of this method below. The example below shows a heading which, the user has added an inline CSS style formatting to. With the code above showing CSS changing the color of the heading to purple, white it prints 'Purple headings are fun!' on the screen.
Advantage
- This type of coding is best for testing as the user can write the CSS that they would like to implement on a certain part of the website to test whether that style change fits their needs or not, without having the need to manipulate anything else on the website.
- Suitable for a 1 page website with limited tags due to inline tags being fairly simple on lightweight websites. This makes the webpage also not require having an additional file, as an external CSS format requires the user to do so.
- If you only want to make one change, you can do so with inline CSS formats as these override any other types of CSS implementations on the webpage, giving the user much more control over the singular element of the webpage that they would like to change in order to suit their needs.
Disadvantage
- Very time consuming when it is for a large website where every line would require an inline CSS. This is because the user will have to manipulate with every single element of the website if they require having a complete design change of the website which is just not convenient for the developer as they will have to go to every single element of the page to change the layouts and the styling of it.
- If there is another CSS implementation along with inline CSS, inline CSS will not let the other implementation work until inline is removed.
- Having inline CSS in a web page will increase the file size and will slow everything down including page load times.
Embedded
Embedded is another form of CSS implementation in a HTML file where CSS is still internal to the code but it is not inline with the code itself but it is placed in the page itself where the HTML is, it is specifically placed in the <head> section of the page. Each piece of code must be identified by a name which then will be used in the embedded CSS which would then match up the names and apply the chosen settings to the chosen piece of code. Which makes this type of CSS implementation very similar to inline, except the CSS defines the whole tag, instead of one singular piece of content of the page.
An example of Embedded CSS is shown below. In the example, there is a div tag in the body which presents a piece of text on the screen when it is run, this text has a defined name called"Boxmodel". The CSS is shown in the <head> tag of the webpage where the predefined name of the div tag i.e. #Boxmodel has CSS applied to it and changes the various styling of the div tag such as the margin being defined as 30px and the border being defined as 10px with a solid black fill, etc.
An example of Embedded CSS is shown below. In the example, there is a div tag in the body which presents a piece of text on the screen when it is run, this text has a defined name called"Boxmodel". The CSS is shown in the <head> tag of the webpage where the predefined name of the div tag i.e. #Boxmodel has CSS applied to it and changes the various styling of the div tag such as the margin being defined as 30px and the border being defined as 10px with a solid black fill, etc.
- This type of CSS implementation is much more time efficient than inline as this does allow the developer of the website to tweak with the CSS of an element of the webpage as a whole defined tag, as opposed to individually changing the CSS for every single line of code.
- The disadvantage of using this type of CSS implementation type is that it is limited to one webpage. This makes it harder for the developer to keep a uniform look to the website, if required to do so as the same CSS will not be able to transfer its styles to different webpages and limit itself to the webpage it was built on, hence why the External implementation style is widely used by developers in creating larger websites than the ones that are limited to only one or two webpages.
External
External is one of the most professional implementation of CSS. This is implemented in a different file to the HTML however saved in the same location as the HTML file so they can work in conjunction. This is a type of implementation used on most websites with multiple webpages. The CSS is in a separate file. Each line of code in the HTML file must be given an identity which should match up a section of the CSS code which contains all the customization of the very line that the developer has written. This type of CSS can then be used to allow different webpages on the same website to communicate with the same CSS style sheet and allow the developer to keep a very uniform look to the website. The example below shows the CSS being in an external source named 'style.css' which is defined in the HTML file with the <link> and <href> tags in the head of the document, and it has three different predefined tags called, '#circle', '#circle2' and '#circle3', which are three different named tags in the HTML file. Each tag customizes different aspects of the defined tags such as the first one defines the left margin to be 5px and background to be red, etc.
The HTML file. |
The CSS style-sheet. |
Advantage
- It is easy for the developer to use external implementation if the webpage consists of two or more pages as one CSS file applies to all of the HTML tags.
- Separate files makes the website smaller in size as they will only have to load the HTML file which makes it faster to load due to smaller files.
- The developer also has full control over the structure of the HTML regardless of it being in a separate file. The whole webpage, if it needs any additional customization, the developer only has to change it once in the code and that change will take place on the whole website.
Disadvantage
- There are two separate files that require to be downloaded from the server which can slow the process down and take more time before the website is published. This makes this style type to not be as efficient for small websites where the developer could either use inline or embedded CSS implementation styles, as they could reduce the load up times for those smaller websites, while an external CSS style sheet will slow down those lightweight websites.