Jump to content

how to align image in HTML?

Go to solution Solved by Naeaes,

This is pretty crude but works. Put <center> before and </center> after.

as in:

<!DOCTYPE html>
<html>
	<head>
		<title>my Page</title>
	</head>
	<body style="background-color: green">
<center>
	    <img src= https://dncache-mauganscorp.netdna-ssl.com/thumbseg/1533/1533681-bigthumbnail.jpg ALT="logo"/>
</center>	    
	    <h1 style="text-align: center"> About Me </h1>
	</body>
</html>

 

this is my code 

 

<!DOCTYPE html>
<html>
	<head>
		<title>my Page</title>
	</head>
	<body style="background-color: green">
	    <img src= https://dncache-mauganscorp.netdna-ssl.com/thumbseg/1533/1533681-bigthumbnail.jpg ALT="logo" align=center />
	    
	    <h1 style="text-align: center"> About Me </h1>
	
	
	
	
	
	
	</body>
</html>

i googled how to and everything i saw made you put

ALT="anything"

and then

align=center

i did that and the picture is still on the left. any idea?

 

Link to comment
https://linustechtips.com/topic/579324-how-to-align-image-in-html/
Share on other sites

Link to post
Share on other sites

This is pretty crude but works. Put <center> before and </center> after.

as in:

<!DOCTYPE html>
<html>
	<head>
		<title>my Page</title>
	</head>
	<body style="background-color: green">
<center>
	    <img src= https://dncache-mauganscorp.netdna-ssl.com/thumbseg/1533/1533681-bigthumbnail.jpg ALT="logo"/>
</center>	    
	    <h1 style="text-align: center"> About Me </h1>
	</body>
</html>

 

Link to post
Share on other sites

FYI - You are declaring HTML5, which has deprecated the align attribute.  Use CSS instead: 

 

<!DOCTYPE html>
<html>
 <style>
  img {
   display: block;
   margin:  0 auto;
  }
  
 </style>
 <head>
  <title>my Page</title>
 </head>
 <body style="background-color: green">
  
 
 
     <h1 style="text-align: center"> About Me </h1>
 
 
 
 
 
 
 </body>
</html>
Link to post
Share on other sites

1 minute ago, cpuwaiy said:

FYI - You are declaring HTML5, which has deprecated the align attribute.  Use CSS instead: 

 


 

well im still in the basics of HTML from code academy i dont think its HTML5 but idk how different that is. im just starting to learn the basics of CSS too

 

Link to post
Share on other sites

7 minutes ago, GreezyJeezy said:

well im still in the basics of HTML from code academy i dont think its HTML5 but idk how different that is. im just starting to learn the basics of CSS too

<!doctype html> means that you're telling the browser you're using HTML5. Most browsers will still account for invalid HTML, but it's inconsistent 

 

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to post
Share on other sites

Just now, Hazy125 said:

<!doctype html> means that you're telling the browser you're using HTML5. Most browsers will still account for invalid HTML, but it's inconsistent 

 

well im learning it on codecademy thats what it said to put. is it wrong? 

 

Link to post
Share on other sites

1 minute ago, GreezyJeezy said:

well im learning it on codecademy thats what it said to put. is it wrong? 

Not sure. I'd probably have to look over the course.

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to post
Share on other sites

<!DOCTYPE html>
<html>
 <style>
  img {
   display: block;
   margin:   auto;
  }
  
 </style>
 <head>
  <title>my Page</title>
 </head>
 <body style="background-color: green">
  

     <img src= https://dncache-mauganscorp.netdna-ssl.com/thumbseg/1533/1533681-bigthumbnail.jpg ALT="logo" />

     <h1 style="text-align: center"> About Me </h1>
 
 
 
 
 
 
 </body>
</html>

 

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×