
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to set the horizontal alignment of an element with JavaScript?
To align the element horizontally, use the cssFloat property.
Example
You can try to run the following code to set the horizontal alignment of an element with JavaScript −
<!DOCTYPE html> <html> <body> <img id="myID" src="https://www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg" width="300" height="300"> <p>This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. </p> <button type="button" onclick="display()">Align Horizontally</button> <script> function display() { document.getElementById("myID").style.cssFloat = "right"; } </script> </body> </html>
- Related Articles
- How to set the horizontal alignment of text with JavaScript?
- How to set the vertical alignment of the content in an element with JavaScript?
- How to set the padding of an element with JavaScript?
- How to set the height of an element with JavaScript?
- How to set the margins of an element with JavaScript?
- How to set the top position of an element with JavaScript?
- How to set the bottom padding of an element with JavaScript?
- How to set the left padding of an element with JavaScript?
- How to set the top padding of an element with JavaScript?
- How to set the right padding of an element with JavaScript?
- How to set the left margin of an element with JavaScript?
- How to set the maximum height of an element with JavaScript?
- How to set the bottom margin of an element with JavaScript?
- How to set the top margin of an element with JavaScript?
- How to set the right margin of an element with JavaScript?

Advertisements