# Styling elements using the style attribute in JavaScript

Let's now learn how to add CSS styles to elements. This is done by changing the attribute `style`. For example, to change the color, you need to build the following chain: `elem.style.color`, and assign the desired color value to it.

Let's look at an example. Let's say we have this element:

`<p id="elem">text</p>`

Let's make this element red:

`let elem = document.querySelector('#elem'); elem.style.color = 'red';`

Given a div and a button. On click on the button, set a width, height, and border to the div.

← →
↑
en ru