Ionic Framework Tutorial - Build Your First Cross-Platform App
Ionic Framework Tutorial - Build Your First Cross-Platform App
Ryan Thelin
Today, we’ll get you started with Ionic, show you how it fits with
other web technologies, and help you create your first Ionic app.
What is Ionic?
How does Ionic work?
Getting started with Ionic
Make your first Ionic App
Tour of Ionic React code
What to learn next
What is Ionic?
Ionic even allows you to develop Ionic Native apps without any
framework.
https://www.educative.io/blog/ionic-framework-tutorial#what 2/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
The embedded browser separates the source code from the device
and acts as a translator between the behavior outlined in the code
and the specifics of the device. This platform-specific tuning allows
you to create apps that perform and look great on any Ionic-
supported platform.
Platform-specific tuning
Backend agnostic
Extensive built-in UI options and elements
Supported by top mobile and web platforms
Easy to pick up for those experienced in Sass, CSS, or HTML
https://www.educative.io/blog/ionic-framework-tutorial#what 3/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
Android iOS
Components allow you to build apps faster because you don’t need
to implement each common function from scratch. As a result, you
can often complete all the barebones functionalities of your app in
just a single sitting.
If you want to go beyond the standard library, you can also create
custom Components. Custom Components can be reused across your
application from then on.
const fruit = [
'Apples',
'Oranges',
'Grapes',
'Peaches'];
return (
<div>
<h1>Hello, Ionic</h1>
<p>Welcome to our app!</p>
<h2>Here are some fruits</h2>
<ul>
{fruit.map((f) => <li>{f}</li>)}
</ul>
</div>
);
https://www.educative.io/blog/ionic-framework-tutorial#what 4/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
Cordova
Ionic apps become hybrid apps with the inclusion of mobile app
development framework Apache Cordova or Capacitor. These
programs create the embedded browser layer that allows Ionic’s
web content to work in a native app. Once wrapped up with the
embedded browser, your app functions as a native app and can be
deployed to app stores on iOS, Android, Electron, or to the web as a
PWA.
Cordova
Ionic
Other frameworks
Ionic is often paired with other front-end frameworks like React and
Angular.
https://www.educative.io/blog/ionic-framework-tutorial#what 5/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
Installation
You’ll need Node.js installed to install Ionic. We’ll install the Cordova
version of Ionic that includes both softwares.
Wait for the command to run its course, and you’ll have everything
you need!
https://www.educative.io/blog/ionic-framework-tutorial#what 6/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
Hello World
Now we’ll make a basic HelloWorld app to show you the ropes.
Step 1
First, create a folder, helloworld , for your project with the following
command:
Step 2
cd helloworld
Step 3
The other files in this section will be home.scss , which is the page to
write your CSS code, and home.ts , where you can write TypeScript
code.
https://www.educative.io/blog/ionic-framework-tutorial#what 7/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
Step 4
Delete any current text in the home.html file and replace it with the
following:
<ion-header>
<ion-navbar>
<ion-title>
Ionic Project
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<h2>Hello World </h2>
</ion-content>
The syntax for this section is nearly identical to HTML syntax. Our
helloworld page is titled “Ionic Project” within the <ion-title>
field. The only content in our app is the term “Hello World” within
the h2 field.
Step 5
ionic serve
Once your app is running, type localhost:8100 into your URL bar to
view the web app content.
If you don’t want to generate the files on your end, you can
follow along using the zip file below.
ionic-react-example-app-educative.zip
(/api/page/6296094892359680/image/download/6280028170485760/educative
-code-widget.zip)
(/api/page/6296094892359680/image/download/6280028170485760/educative
-code-widget.zip)
https://www.educative.io/blog/ionic-framework-tutorial#what 9/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
index.tsx
Open up the index.tsx file. This file is long, but the most important
parts are at the top.
index.tsx
https://www.educative.io/blog/ionic-framework-tutorial#what 10/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
index.html
This file contains many tags in <head> that control how the
application renders on mobile devices. Ionic has already optimized
this file so you should rarely have to alter it. Instead, make changes
to the index.tsk file.
1 <!DOCTYPE html>
2 <html lang="en">
3
4 <head>
5 <meta charset="utf-8" />
6 <title>Ionic App</title>
7
8 <base href="/" />
9
10 <meta name="color-scheme" content="light
11 <meta name="viewport"
12 content="viewport-fit=cover, width=dev
13 <meta name="format-detection" content="t
14 <meta name="msapplication-tap-highlight"
15
16 <link rel="manifest" href="%PUBLIC_URL%/m
17 <link rel="shortcut icon" type="image/png
18
19 <!-- add to homescreen for ios -->
20 <meta name="apple-mobile-web-app-capable
21 <meta name="apple-mobile-web-app-title"
22 <meta name="apple-mobile-web-app-status-
23 </head>
24
25 <body>
26 <div id="root"></div>
27 </body>
28
29 </html>
30
index.html
https://www.educative.io/blog/ionic-framework-tutorial#what 11/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
The body tag on line 25-27 contains a div paired to root to allow
index.html to connect with index.tsx .
App.tsx
This file defines the App component. This is really where your
application’s React code starts. App is defined as a constant arrow
function, of the type React.FC . FC is short for FunctionComponent .
App.tsx
https://www.educative.io/blog/ionic-framework-tutorial#what 12/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
Page.tsx
Page is another component similar to App . The primary difference
is that the FunctionComponent is a generic of type
RouteComponentProps . This is what allows the Router to pass those
https://www.educative.io/blog/ionic-framework-tutorial#what 13/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
route parameters.
Page.tsx
Menu.tsx
Now open the menu.tsx file. This is where the side menu
appearance and categories are defined.
Near the top of the file, it defines an AppPage interface, used to hold
common properties about a page, such as its URL, icons, and title.
1 interface AppPage {
2 url: string;
3 iosIcon: string;
4 mdIcon: string;
5 title: string;
6 }
https://www.educative.io/blog/ionic-framework-tutorial#what 15/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
React markup in Menu.tsx
And there you have it! Now that you understand each of the parts of
this beginner application, you can start adding your own personal
touches.
The next steps for mastering Ionic with React are to learn:
To help you advance in half the time, Educative has created the
Developing Mobile Apps with Ionic and React
(https://www.educative.io/courses/developing-mobile-apps-with-
ionic-and-react) course. This course hands-on lessons on the
creation, optimization, and deployment of cutting-edge Ionic apps.
https://www.educative.io/blog/ionic-framework-tutorial#what 16/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
By the end, you’ll have the expertise to manipulate all of the basic
Ionic templates and have intimate knowledge on how to customize
components to your needs.
Happy learning!
WRITTEN BY
Ryan Thelin
Full Name
Subscribe
https://www.educative.io/blog/ionic-framework-tutorial#what 17/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
Today, we help you start your Today, we'll help you get familiar
Spring Framework journey by with React by building Instagram's
exploring the advantages and… UI.
Ryan Thelin
May 5 · 2021
(/blog/advanced-yaml-syntax-cheatsheet)
(/)
LEARN
Courses
(/explore)
(/explore/early-access)
Edpresso
(/edpresso)
Blog
(/blog)
Pricing
(/unlimited)
(/trial)
https://www.educative.io/blog/ionic-framework-tutorial#what 18/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
For Business
(/business)
CodingInterview.com
(//codinginterview.com/)
SCHOLARS H IPS
For Students
(/github-students)
For Educators
(/github-educators)
CONTRIBUTE
Become an Author
(/authors)
Become an Af liate
(/af liate)
LEGAL
Privacy Policy
(/privacy)
Terms of Service
(/terms)
(/enterprise-terms)
MORE
Our Team
(/team)
Careers
(//angel.co/educativeinc/jobs)
For Bootcamps
(//try.educative.io/bootcamps)
(/blog/enterprise)
Quality Commitment
(/quality)
FAQ
(/courses/educative-faq)
Contact Us
https://www.educative.io/blog/ionic-framework-tutorial#what 19/20
5/8/2021 Ionic Framework Tutorial: Build your first cross-platform app
(/contactUs)
(//linkedin.com/company/educative- (//www.youtube.com/channel/UCT_8FqzTIr2Q1BOtvX_DPPw/?
educativeinc) (//twitter.com/educativeinc) (//educativesess
inc/) sub_con rmation=1)
https://www.educative.io/blog/ionic-framework-tutorial#what 20/20