Styling Elements

Let's learn how to add style properties to existing elements on a web page.

JavaScript not only lets you interact with your web page structure but also changes the style of the elements. It’s time to learn how. Here is the example HTML content used in the following paragraphs.

Html content

And here is the associated CSS stylesheet. The rules in a stylesheet determine the appearance of elements on a page. Here, the one element we’re adjusting via CSS is the element with the para ID. Its text will be blue and in italics.

Style the element in CSS

Style property

DOM elements are equipped with a property called style, which returns an object representing the HTML element’s style attribute. This object’s properties match up to its CSS properties. By defining these properties with JavaScript, ...

Access this course and 1400+ top-rated courses and projects.