p5.js | style() Function
The style() function is used to set the style property of an element with the given value. If this function contains single parameter then use .style() function to return the value of the given property.
Note: This function requires the p5.dom library. So add the following line in the head section of the index.html file.
<script language=”javascript” type=”text/javascript” src=”path/to/p5.dom.js”></script>
Syntax:
style( property )
or
style( property, value )
Parameters:
- property: This parameter holds the CSS property name.
- value: This parameter holds the value of CSS property.
Return Value: This function returns the value of property.
Example 1:
function setup() { // Create canvas of size 400*200 createCanvas(400, 200); // Set background color background('green'); // Create an input element var input_val = createInput(''); // Set the attribute and its value input_val.attribute('value', 'Welcome to GeeksforGeeks'); // Set the position of div element input_val.position(60, 80); // Set width of input field input_val.style('width', '250px'); // Set font-size of input text input_val.style('font-size', '20px'); } |
Output:

Example 2:
function setup() { // Create canvas of size 400*200 createCanvas(400, 200); // Set background color background('green'); // Create an input element var div_cont = createDiv('Welcome to GeeksforGeeks'); // Set the position of div element div_cont.position(60, 80); // Set the font color div_cont.style('color', '#ffffff'); // Set width of input field div_cont.style('width', '250px'); // Set font-size of input text div_cont.style('font-size', '20px'); } |
Output:

Recommended Posts:
- How to remove style added with .css() function using JavaScript?
- How to remove CSS style of <style> tag using JavaScript/jQuery ?
- How to style a dropdown using CSS?
- HTML | Style Tag
- How to style a checkbox using CSS?
- How to combine ng-class with ng-style?
- HTML | DOM Style right Property
- HTML | DOM Style top Property
- How to set CSS style to half of a character ?
- CSS | outline-style Property
- CSS | border-right-style Property
- CSS | border-top-style Property
- CSS | transform-style Property
- HTML | style attribute
- CSS | border-style Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.



