Image style

In this article we are going to learn about image style, width, height, border and radius in css, how to customize or style the image in html.

Image style

Image styling is a way of giving images some good features to look nice for good view in html using just css properties.


Width

We can use width property to specify the width of the image.

Let us add two images in html page with a width property applied, copy and paste below code.

<!DOCTYPE html>

<head>

<style>

.img-width-css-example {

width: 20%;

}

<style/>

</head>

<body>

<img class="img-width-css-example" src="images/icon.png" alt="scienceinlesotho icon">

<img width="20%" src="images/icon.png" alt="scienceinlesotho icon">

</body>

</html>


So, we should have the following results.

scienceinlesotho icon scienceinlesotho icon

Height

We can use height property to specify the height of the image.

Let us add two images in html page with height property applied, copy and paste below code.

<!DOCTYPE html>

<head>

<style>

.img-height-css-example {

height: 15%;

}

<style/>

</head>

<body>

<img class="img-height-css-example" src="images/icon.png" alt="scienceinlesotho icon">

<img height="15%" src="images/icon.png" alt="scienceinlesotho icon">

</body>

</html>


So, we should have the following results.

scienceinlesotho icon scienceinlesotho icon

Border

We can use border property to specify the border of the image.

Let us add the image in html page with border property applied, copy and paste below code.

<!DOCTYPE html>

<head>

<style>

.img-border-example {

border: 1px solid red;

}

<style/>

</head>

<body>

<img class="img-border-example" src="images/icon.png" alt="scienceinlesotho icon">

</body>

</html>


So, we should have the following results.

scienceinlesotho icon

Radius

We can use border radius property to specify the border radius of the image.

Let us add the image in html page with border radius property applied, copy and paste below code.

<!DOCTYPE html>

<head>

<style>

.img-border-radius-example {

border: 1px solid red;

border-radius: 50%;

}

<style/>

</head>

<body>

<img class="img-border-radius-example" src="images/icon.png" alt="scienceinlesotho icon">

</body>

</html>


So, we should have the following results.

scienceinlesotho icon

Conclusion

In this article we learnt about image style, width, height, border and radius in css, how to customize or style the image in html.