How to center a URL in a html document
Hi everyone I'm a beginner in HTML, and I need to know how to center an URL inside my web page, for example :
<a href="http://www.google.com"> Click Here to Open Google </a>
I tried to use the tag, and the STYLE attribute but it doesn't work.
Can some one help me to make it please ?
You could try in your css file:
Hope this helps, personally I would add a class name to your a link such as google-link, otherwise this a style will effect all future anchor links :)
So in html file:
<a href="www.google.com" class="google-link">Click here to open google</a>
Then in css file:
In addition your href needs to include a = after it:
i think the reason is because your DOM only covers the width of your text link which is "Click Here to Open Google". so centering it with the "center" tag will not give what you want.
Please try this:
<div style='width:100%; text-align:center;'><a href="http://www.google.com"> Click Here to Open Google </a>
Explanation is, you created a "div" element and gave it a 100% width, then specify that anything inside it will be center aligned.
You can simply try this solution. In above, your href should look like below code and then you can use style which will center your link.
<a href:"http://www.google.com" style="text-align:center"> Click Here to Open Google <\a>
Or else you can try
<div text-align="center">your link code here(<a href="your link"> </a>)......</div>
This will solve your problem. Kindly check the codepen link for demo:
For more info about css display block, you can refer w3 schools link: