Centering an image

Centering an image
0.0 0

#1

I just began my first project and am trying to center an image in it. I have looked on a few websites and searched through the freecodecamp projects I have previously completed and can’t find anything that will work.
Here is my code so far:

<style>
  .green-text {
    color:green;
  }
  .smaller-image {
    width:500px
</style>
<h1 class="green-text text-center">Karl Marx</h1>
<a href="#"><img class="smaller-image" src='//discourse-user-assets.s3.amazonaws.com/original/3X/8/c/8cb74b7339564360d451b4f3484be5340d0da18f.jpg'></a>

Thanks


#2

You might want to look into margin, or text center

btw, you’re missing a closing bracket and the declarations should not really be in one line unless minimized for production purposes


#3

You should add text-align: center to the container of the img tag. This will center it horizontally.


#4

try placing a center element right before the image element and remember to close it.


#5

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.