<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alexis Guzman</title>
    <description>The latest articles on DEV Community by Alexis Guzman (@codingcodax).</description>
    <link>https://dev.to/codingcodax</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F420175%2Fcd8dcf91-d8cd-4190-9084-ca60458258fc.png</url>
      <title>DEV Community: Alexis Guzman</title>
      <link>https://dev.to/codingcodax</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codingcodax"/>
    <language>en</language>
    <item>
      <title>How to install Node js on Linux</title>
      <dc:creator>Alexis Guzman</dc:creator>
      <pubDate>Wed, 03 Nov 2021 22:41:18 +0000</pubDate>
      <link>https://dev.to/codingcodax/how-to-install-node-js-on-linux-5gj0</link>
      <guid>https://dev.to/codingcodax/how-to-install-node-js-on-linux-5gj0</guid>
      <description>&lt;p&gt;When we start using Linux, one of the first doubts is how to install our favorite applications. As developers, we need several tools, one of the most common is Node.js and NPM. Let's see what is Node.js, NPM and how to install them in Linux.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Node JS?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://nodejs.org/"&gt;Node.js&lt;/a&gt; is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside of a web browser. Node.js is a popular, lightweight web framework for beginners, and it is used by many big companies like Netflix and Uber.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is NPM?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/"&gt;NPM&lt;/a&gt; is the default package manager for Node.js projects. NPM includes a command-line tool (CLI) that give you access to the &lt;a href="https://docs.npmjs.com/cli/v7/using-npm/registry"&gt;NPM package registry&lt;/a&gt;. The registry stores the numerous JavaScript packages made available through the NPM CLI, along with their metadata. The &lt;a href="https://www.npmjs.com/"&gt;NPM website&lt;/a&gt; gives you an easy way to search for JavaScript packages and read information about them. The &lt;code&gt;package.json&lt;/code&gt; file that is generated by the NPM CLI helps you manage project dependencies. It also ensures consistent project installations across environments.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;There are several ways to install Node.js, but probably the most popular is using Node Version Manager (NVM).&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is NVM?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/nvm-sh/nvm"&gt;NVM&lt;/a&gt; allows you to quickly install and use different versions of Node via the command line. Is a version manager for Node.js, designed to be installed per-user, and invoked per-shell. NVM works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash).&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;

&lt;p&gt;You can install NVM using cURL or Wget, you only need to execute one of the two commands in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-o-&lt;/span&gt; https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wget &lt;span class="nt"&gt;-qO-&lt;/span&gt; https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To verify that it is installed correctly just type &lt;code&gt;nvm -v&lt;/code&gt; and it should return the latest version of NVM, for example &lt;code&gt;0.38.0&lt;/code&gt;. To upgrade NVM, just run the same command.&lt;/p&gt;

&lt;p&gt;There are some times that when we finish installing NVM, we run &lt;code&gt;nvm -v&lt;/code&gt;, and instead of getting something like &lt;code&gt;0.38.0&lt;/code&gt; we get &lt;code&gt;nvm: command not found&lt;/code&gt;. But it is not the end of the world, in these cases it is necessary to close our terminal, open a new one and try &lt;code&gt;nvm -v&lt;/code&gt; again.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;To install the latest version of Node.js, do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;install &lt;/span&gt;node &lt;span class="c"&gt;# "node" is an alias for the latest version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To install a specific version of Node.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;install &lt;/span&gt;14.7.0 &lt;span class="c"&gt;# or 16.3.0, 12.22.1, etc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To install the long-term support (LTS) of Node.js (the one I recommend):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--lts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;Now just verify that Node.js and NPM are installed correctly, just run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="c"&gt;# should return v16.13.0, v14.17.5, etc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="c"&gt;# should return 8.1.2, 8.1.0, etc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;And that's it! We already have Node.js and NPM in our Linux in a quick and easy way.&lt;br&gt;
For more information check the NVM repository, there is more advanced information, frequent problems, and also where you can report a bug.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;If you know other/better way please leave below in the comments. Share this post to whoever you think will help. I'll see you later.&lt;/p&gt;

</description>
      <category>npm</category>
      <category>node</category>
      <category>linux</category>
      <category>bash</category>
    </item>
    <item>
      <title>Build React and Next applications most fast and efficiently</title>
      <dc:creator>Alexis Guzman</dc:creator>
      <pubDate>Thu, 13 May 2021 21:49:48 +0000</pubDate>
      <link>https://dev.to/codingcodax/build-react-and-next-applications-most-fast-and-efficiently-5i4</link>
      <guid>https://dev.to/codingcodax/build-react-and-next-applications-most-fast-and-efficiently-5i4</guid>
      <description>&lt;p&gt;Hello, world. Usually, developers spent a lot of time installing dependencies, creating folders, etc, before having our initial configuration and start working on the application.&lt;/p&gt;

&lt;p&gt;The goal of ReexJs CLI is that we can start working on our application without worrying about the initial configuration.&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://github.com/a12989x/reexjs-cli/" rel="noopener noreferrer"&gt;ReexJs&lt;/a&gt; we can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;react.js&lt;/a&gt; or &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;next.js&lt;/a&gt; app.&lt;/li&gt;
&lt;li&gt;Create folders with a list of predefined lists and add custom folders.&lt;/li&gt;
&lt;li&gt;Create routes if your choose react or pages for next.&lt;/li&gt;
&lt;li&gt;Install normal dependencies and dev dependencies.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/" rel="noopener noreferrer"&gt;Node Js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;An active internet connection for CLI to work.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;ReexJs use &lt;code&gt;npx create-react-app &amp;lt;appname&amp;gt;&lt;/code&gt; or &lt;code&gt;npx create-next-app &amp;lt;appname&amp;gt;&lt;/code&gt; and &lt;code&gt;spawn&lt;/code&gt; from &lt;code&gt;child_process&lt;/code&gt; to run one of the two commands.&lt;/p&gt;

&lt;p&gt;To create the folders use &lt;code&gt;mkdirSync&lt;/code&gt; from &lt;code&gt;fs&lt;/code&gt;, and depending on if you previously choose react.js or next.js folders will be created in different paths, for react.js these will be created in &lt;code&gt;src/&lt;/code&gt;, and for next.js folder will be created in the root path &lt;code&gt;/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Finally to install the dependencies &lt;code&gt;spawn&lt;/code&gt; is also used when installing the framework. &lt;code&gt;npm i &amp;lt;dependencies&amp;gt;&lt;/code&gt; for normal dependencies and &lt;code&gt;npm i -D &amp;lt;devDependencies&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use it
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Install &lt;a href="https://github.com/a12989x/reexjs-cli/" rel="noopener noreferrer"&gt;ReexJs&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/" rel="noopener noreferrer"&gt;Npm&lt;/a&gt;: &lt;code&gt;npx reexjs-cli&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://yarnpkg.com/" rel="noopener noreferrer"&gt;Yarn&lt;/a&gt;: &lt;code&gt;yarn reexjs-cli&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Choose the app name. By default is &lt;em&gt;reexjs-app.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Choose the framework between react.js and next.js.&lt;/li&gt;
&lt;li&gt;Select predefined folders and add custom folders.&lt;/li&gt;
&lt;li&gt;Write your normal dependencies and dev dependencies.&lt;/li&gt;
&lt;li&gt;Finally change the directory and run &lt;code&gt;npm start&lt;/code&gt; or &lt;code&gt;npm run dev&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2cknqqh4l4bbkwvc0nxs.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2cknqqh4l4bbkwvc0nxs.gif" alt="intro"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;ReexJs can save us time and start working on our application without worrying about the initial configuration.&lt;/p&gt;

&lt;p&gt;So take a ☕ and relax.&lt;br&gt;
&lt;/p&gt;

&lt;br&gt;
Thank you for reading 🙏&lt;br&gt;
If you enjoyed this article or found it helpful, give it a thumbs-up 👍, and if you have an idea to improve the application or any type of suggestion please leave it below in the comments 💬. 

&lt;p&gt;Feel free to connect 👋&lt;br&gt;
&lt;a href="https://www.buymeacoffee.com/codax" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.buymeacoffee.com%2Fbuttons%2Fv2%2Fdefault-violet.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to uppercase the first letter of a string in JavaScript</title>
      <dc:creator>Alexis Guzman</dc:creator>
      <pubDate>Fri, 07 May 2021 22:50:24 +0000</pubDate>
      <link>https://dev.to/codingcodax/how-to-uppercase-the-first-letter-of-a-string-in-javascript-5bi9</link>
      <guid>https://dev.to/codingcodax/how-to-uppercase-the-first-letter-of-a-string-in-javascript-5bi9</guid>
      <description>&lt;p&gt;JavaScript offers many ways to capitalize a string to make the first character uppercase. Learn the various ways, and also find out which one you should use, using plain JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. chartAt + slice
&lt;/h2&gt;

&lt;p&gt;The first way to do this is through a combination of &lt;code&gt;cartAt()&lt;/code&gt; and &lt;code&gt;slice()&lt;/code&gt;. With  &lt;code&gt;chartAt()&lt;/code&gt; uppercases the first letter, and with &lt;code&gt;slice()&lt;/code&gt; slices the string and returns it starting from the second character:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;codax&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nameCapitalized&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;charAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// expected output: "Codax" &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can create a function to do that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;capitalize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;charAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;capitalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;codax&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Codax"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Replace function
&lt;/h2&gt;

&lt;p&gt;My favorite is with &lt;code&gt;replace()&lt;/code&gt; because I love regex (even if I'm not an expert) and regex is more customizable in general.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;codax&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nameCapitalized&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;\w&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;
&lt;span class="c1"&gt;// expected output: "Codax"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also make it a function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;capitalize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;\w&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;capitalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;codax&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Codax"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;For readability, I recommend the first option (&lt;code&gt;chartAt&lt;/code&gt; + &lt;code&gt;slice&lt;/code&gt;), and for speed, I recommend the second option (&lt;code&gt;replace&lt;/code&gt;).&lt;br&gt;
If you know other/better ways please leave below in the comments, or how to improve on the ones mentioned here.&lt;br&gt;
Thanks.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>string</category>
    </item>
    <item>
      <title>How to center elements with CSS</title>
      <dc:creator>Alexis Guzman</dc:creator>
      <pubDate>Thu, 28 Jan 2021 21:38:30 +0000</pubDate>
      <link>https://dev.to/codingcodax/how-to-center-elements-with-css-5di7</link>
      <guid>https://dev.to/codingcodax/how-to-center-elements-with-css-5di7</guid>
      <description>&lt;p&gt;Knowing how to center things with css is very necessary for our day to day as web developers. There are several ways to achieve the same, so it can get us confused. Today we are going to learn how to center things horizontally, vertically and both (horizontally and vertically) fully responsive.&lt;/p&gt;

&lt;p&gt;We will work with two divs, one as a parent element and the other as a child.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"parent"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"child"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1. Horizontally
&lt;/h3&gt;

&lt;p&gt;Center an element &lt;code&gt;display: block;&lt;/code&gt; requires a fixed width, since it takes all the available width or, failing that, transform it to &lt;code&gt;display: inline-block;&lt;/code&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VXjHHSLh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.notion.so/image/https%253A%252F%252Fs3-us-west-2.amazonaws.com%252Fsecure.notion-static.com%252F0b7662c9-924b-4973-ad0f-7363b9b7b7f6%252FCenter_css%281%29.jpg%3Ftable%3Dblock%26id%3Da5c10f02-1c0b-4b4f-93a8-6e277311203b%26cache%3Dv2" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VXjHHSLh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.notion.so/image/https%253A%252F%252Fs3-us-west-2.amazonaws.com%252Fsecure.notion-static.com%252F0b7662c9-924b-4973-ad0f-7363b9b7b7f6%252FCenter_css%281%29.jpg%3Ftable%3Dblock%26id%3Da5c10f02-1c0b-4b4f-93a8-6e277311203b%26cache%3Dv2" alt="center-horizontally"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Method margin-auto:&lt;/strong&gt;&lt;br&gt;
Giving it automatic margin from left to right, it automatically centers the element horizontally and is fully responsive.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.child&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using Flexbox:&lt;/strong&gt;&lt;br&gt;
Flexbox is a more useful feature within css. We use it a lot for the layout. We can use &lt;code&gt;justify-content&lt;/code&gt; in the parent element to achieve our goal. And it is also responsive. (Remember that by default &lt;code&gt;flex-direction&lt;/code&gt; is &lt;code&gt;row&lt;/code&gt; so all child elements will be placed in a horizontal row, if you want them to be placed vertically use &lt;code&gt;flex-direction: column;&lt;/code&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.parent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Vertically
&lt;/h3&gt;

&lt;p&gt;Centering items vertically is confusing, so let's see how to get it right.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8nM25LyJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.notion.so/image/https%253A%252F%252Fs3-us-west-2.amazonaws.com%252Fsecure.notion-static.com%252Fb630de56-6c13-4801-96f7-860fd63a6016%252FCenter_css%281%29.jpg%3Ftable%3Dblock%26id%3D29640023-d231-4f19-8424-d9709ab8db56%26cache%3Dv2" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8nM25LyJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.notion.so/image/https%253A%252F%252Fs3-us-west-2.amazonaws.com%252Fsecure.notion-static.com%252Fb630de56-6c13-4801-96f7-860fd63a6016%252FCenter_css%281%29.jpg%3Ftable%3Dblock%26id%3D29640023-d231-4f19-8424-d9709ab8db56%26cache%3Dv2" alt="center-vertically"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Using Flexbox(again):&lt;/strong&gt;&lt;br&gt;
Now instead of using &lt;code&gt;justify-content&lt;/code&gt; we will use &lt;code&gt;align-items&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.parent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Both(horizontally and vertically)
&lt;/h3&gt;

&lt;p&gt;Centering elements both horizontally and vertically is very satisfying. We almost always have a situation where we want to center things so let's see 2 ways to do it.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o978WC75--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hhz08acn8uycqldi00gh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o978WC75--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hhz08acn8uycqldi00gh.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;With Flexbox(yes again):&lt;/strong&gt;&lt;br&gt;
As we've seen, flexbox helps us to center things both horizontally and vertically, so what if we put &lt;code&gt;justify-content&lt;/code&gt; and &lt;code&gt;align-items&lt;/code&gt; together?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.parent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using Grid:&lt;/strong&gt;&lt;br&gt;
This is the last method of the post and the fastest. It is my favorite, we can center the elements with only 2 lines of code!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.parent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;place-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;There are many ways to achieve the same, such as using &lt;code&gt;position&lt;/code&gt;, playing with &lt;code&gt;padding&lt;/code&gt; and &lt;code&gt;margin&lt;/code&gt;. Although it generally depends on the situation which method we will use. I recommend learning Flexbox and Grid as it helps us in various ways, reducing our lines of code. Share this post to whoever you think will help.&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
