center tag in html with example







  1. The HTML <center> tag is used to center-align HTML elements.
  2. The HTML <center> tag is deprecated in HTML 4.01 and obsolete in HTML 5.
  3. You should use Cascading Style Sheets (CSS) to center elements.
  4. In particular, see the CSS text-align property.
  5. The <center> tag is supported in all major browsers. However, it is deprecated and should be avoided!.


Example :

     <html>
     <head>
     <title>Center</title>
     </head>
     <body>
     <p>This is the text without center tag.</p>
     <p><center>This is with center tag.</center></p>
     </body>
     </html>
     

Demo :





In the above example, we have rendered two lines. The one line is without center tag and next line is with center tag. The center tag renders the tag in center.



Center and style :



<html>
<head>
<title>CenterStyle</title>
<style type="text/css">
center
{
font-family:comic sans ms;
color:Green;
}
</style>
</head>
<body>
<p>This is the text without center tag.</p>
<center>This is with center tag.</center>
</body>
</html>


Demo :





In the above example, we have rendered center tag. We have also applied CSS to the center tag.



Center and Javascript :



<html>
<head><title>CenterJavascript</title>
<script type="text/javascript">
function center()
{
var element=document.createElement("center");
var text=document.createTextNode("This is center effect.");
element.appendChild(text);
document.getElementById("center").appendChild(element);
}
</script>
</head>
<body>
<div id="center">
</div>
<input type="button" id="b1" value="Press" onclick="center()">
</body>
</html>
     

Demo :





In the above example, we have rendered center tag using javascript. 



0 comments:

Post a Comment