How To Add a Styled Profile Image To Your Webpage With HTML
This tutorial series will guide you through creating and further customizing this website using HTML, the standard markup language used to display documents in a web browser. No prior coding experience is necessary but we recommend you start at the beginning of the series if you wish to recreate the demonstration website.
In this tutorial, we’ll walk through the steps of adding and styling the top profile image as displayed in the demonstration site.
Before we get started, you may want to pick a personal profile photo for including on your site. If you don’t have a profile photo, you can use any image for demonstration purposes or create an avatar through a site like Getavataaars.com. Otherwise, you can use the image from our demonstration site by downloading the image here. (For a refresher on how to add images to webpages using HTML, please visit our tutorial HTML Images from earlier in this tutorial series.)
Once you’ve selected an image, save it as
small-profile.jpg in your
Paste the following
<img> element in between the opening and closing
<div> tags you created in the last tutorial like so:
... <div style="background-image: url('ImageLocation');background-size: cover; height:480px; padding-top:80px;"> <img src="ImageFilePath;" style="height:150px;"> </div> ...
Make sure to switch out the highlighted
src address with the file path of your profile image. Note that we are also using the style attribute to specify the height of the image to 150 pixels. The
<img> element does not require a closing tag.
Save and reload the page in the browser to check your results. You should receive the following:
Your profile image should appear as 150 pixels tall given the height we specified with the
style attribute. It should also located 80 pixels below the top of the
<div> container, given the
top-padding property we specified for the
<div> container in the previous tutorial. Next, let’s add properties to our
style attribute that will give our image a circular shape and a yellow border. We will also add alternative text to improve accessibility for site visitors who use screen readers.
Add the highlighted properties to your
<img src="ImageFilePath" style="height:150px; border-radius: 50%; border: 10px solid #FEDE00;" alt="This is a small profile image of Digital Ocean’s mascot, a blue smiling shark.">
Make sure you still have the correct file path of your image listed as the
src address. Save the file and reload it in the browser. You should receive something like this:
Before moving on, let’s briefly pause to study the code modifications we just made. Setting the
border-radius value to 50% gives the image a circular shape. Setting the border value to
10px solid #FEDE00 gives the image a solid border that is 10 pixels wide and has the hexadecimal color value
You should now know how to add and style a profile image to your website with HTML. We are now ready to add a title and subtitle to the webpage in the next tutorial.