The center() function is used to set the alignment of element into the center either vertically, horizontally, or both, relative to its parent element or according to the body if the element has no parent. If this function does not contain any parameters then the element will align both vertically and horizontally.
Note: This function requires the p5.dom library. So add the following line in the head section of the index.html file.
center( align )
Parameters: This function accepts single parameter align which holds the string ‘vertical’ or ‘horizontal’ to align the element.
Below examples illustrate the center() function in p5.js:
- Differences between HTML <center> Tag and CSS "text-align: center;" Property
- How to horizontally center a div using CSS?
- How to vertically center text with CSS?
- How to make an image center-aligned (vertically & horizontally) inside a bigger div using CSS?
- How to make elements float to center?
- How to center a popup window on screen?
- How to vertically and horizontally align flexbox to center ?
- How to center a div within another div?
- How to Align modal content box to center of any screen?
- How to Align Navbar Items to Center using Bootstrap 4 ?
- How to Align <legend> Tag Text to Center ?
- How to center absolutely positioned element in div using CSS ?
- How to target all Font Awesome icons and align them center?
- How place a checkbox into the center of a table cell?
- How to place table text into center using Bootstrap?
- How to set the dropdown button in the center?
- How to set column in center using Bootstrap 5?
- D3.js bisector.center() Method
- HTML | center Tag
- How to align a logo image to center of navigation bar using HTML and CSS ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.